コード例 #1
0
func (r *Runner) Start() error {
	if r.stopped {
		return errors.New("Cannot restart a runner.")
	}

	numRoutes := r.job.EndRange - r.job.StartRange
	rangeSize := numRoutes / r.numGoRoutines
	ranges := PartitionRange(r.job.StartRange, r.job.EndRange, rangeSize)

	for i := 0; i < r.numGoRoutines; i += 1 {
		r.wg.Add(1)
		go func(id int) {
			defer r.wg.Done()

			job := r.job
			job.StartRange = ranges[id]
			job.EndRange = ranges[id+1]
			p := publisher.NewPublisher(job)
			err := p.Initialize(r.cc)
			if err != nil {
				r.errsChan <- fmt.Errorf("initializing connection: %s", err)
				r.Stop()
				return
			}
			err = p.PublishRouteRegistrations()
			if err != nil {
				r.errsChan <- fmt.Errorf("publishing: %s", err)
				r.Stop()
				return
			}
			for {
				select {
				case <-time.After(r.heartbeatInterval):
					err := p.PublishRouteRegistrations()
					if err != nil {
						r.errsChan <- fmt.Errorf("publishing: %s", err)
						r.Stop()
						return
					}
				case <-r.quitChan:
					// Exit upon closed quit channel
					return
				}
			}
		}(i)
	}

	return nil
}
コード例 #2
0
	validJob := publisher.Job{
		PublishingEndpoint: "pub.end.point",

		BackendHost: "1.2.3.4",
		BackendPort: 1234,

		AppDomain:  "apps.com",
		AppName:    "some-app",
		StartRange: 500,
		EndRange:   505,
	}
	Describe("Initialize", func() {
		It("errors if validation of the job properties fails", func() {
			w := publisher.NewPublisher(publisher.Job{
				PublishingEndpoint: "endpoint",
				BackendHost:        "1.2.3.4",
				BackendPort:        1234,
			})
			createConnection := func(endpoint string) (publisher.PublishingConnection, error) {
				return nil, nil
			}
			err := w.Initialize(createConnection)
			Expect(err).To(HaveOccurred())
			Expect(err).To(MatchError(`Invalid job properties: Missing "AppDomain"`))
		})

		It("errors if the creation of a connection fails", func() {
			w := publisher.NewPublisher(validJob)
			createConnection := func(endpoint string) (publisher.PublishingConnection, error) {
				return nil, errors.New("Unable to create connection")
			}