コード例 #1
0
func startPopulatingRoutes() {
	job := publisher.Job{
		PublishingEndpoint: *natsEndpoint,

		BackendHost: *backendHost,
		BackendPort: *backendPort,

		AppDomain: *appDomain,
		AppName:   *appName,

		StartRange: 0,
		EndRange:   *numRoutes,
	}

	numCPU := runtime.NumCPU()
	// Heuristic to avoid spawning more goroutines than needed
	if *numRoutes < 1000 {
		numCPU = 1
	}
	interval := time.Duration(*heartbeatInterval) * time.Second
	r := runner.NewRunner(createNATSConnection, job, numCPU, interval)

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	// Stop the runner if we receive an interrupt
	go func() {
		sig := <-sigs
		fmt.Fprintf(os.Stderr, "Received signal %s\n", sig)
		r.Stop()
	}()

	err := r.Start()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error starting runner: %s\n", err)
	}
	err = r.Wait()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error running: %s\n", err)
	}
}
コード例 #2
0
		It("publishes once as soon as the runner is started", func(done Done) {
			defer close(done)
			var allMessages string
			msgLock := &sync.Mutex{}
			c := &fakes.FakePublishingConnection{}
			c.PublishStub = func(subj string, data []byte) error {
				msgLock.Lock()
				allMessages = allMessages + string(data)
				msgLock.Unlock()
				return nil
			}
			createConnection := func(endpoint string) (publisher.PublishingConnection, error) {
				return c, nil
			}

			r := runner.NewRunner(createConnection, validJob, numGoRoutines, 10*time.Second)
			err := r.Start()
			Expect(err).ToNot(HaveOccurred())
			r.Stop()
			err = r.Wait()
			Expect(err).ToNot(HaveOccurred())
			Expect(c.PublishCallCount()).To(Equal(5))
			for i := validJob.StartRange; i < validJob.EndRange; i += 1 {
				Expect(allMessages).To(ContainSubstring("some-app-%d.apps.com", i))
			}
		}, 1)
		It("publishes on an interval", func(done Done) {
			defer close(done)
			c := &fakes.FakePublishingConnection{}
			createConnection := func(endpoint string) (publisher.PublishingConnection, error) {
				return c, nil