示例#1
0
func convergeTasks(bbs bbs.ExecutorBBS) {
	statusChannel, releaseLock, err := bbs.MaintainConvergeLock(*convergenceInterval, executorID)
	if err != nil {
		logger.Fatal("converge-lock.acquire-failed", map[string]interface{}{
			"error": err.Error(),
		})
	}

	for {
		select {
		case locked, ok := <-statusChannel:
			if !ok {
				return
			}

			if locked {
				t := time.Now()

				logger.Info("converging", map[string]interface{}{})

				bbs.ConvergeTasks(*timeToClaimTask)

				logger.Info("converged", map[string]interface{}{
					"took": time.Since(t),
				})
			} else {
				logger.Info("converge-lock.lost", map[string]interface{}{})
			}
		case <-stop:
			close(releaseLock)

			for _ = range statusChannel {
			}

			return
		}
	}
}
示例#2
0
func maintainPresence(bbs bbs.ExecutorBBS, ready chan<- bool) error {
	p, statusChannel, err := bbs.MaintainExecutorPresence(*heartbeatInterval, executorID)
	if err != nil {
		ready <- false
		return err
	}

	tasks.Add(1)

	go func() {
		for {
			select {
			case locked, ok := <-statusChannel:
				if locked && ready != nil {
					ready <- true
					ready = nil
				}

				if !locked && ok {
					tasks.Done()
					logger.Fatal("maintain.presence.fatal", map[string]interface{}{})
				}

				if !ok {
					tasks.Done()
					return
				}

			case <-stop:
				p.Remove()

				for _ = range statusChannel {
				}

				tasks.Done()

				return
			}
		}
	}()

	return nil
}