Example #1
0
func leaderStateFn(agent *Agent) handleStateFn {
	agent.changeState("LEADER_STATE")

	leaderTask := agent.advertiseAndRenewLeaderRoleT()
	//TODO: agent.SetupScheduler()
	jobPublisherTask := agent.publishJobOffersT()

	executorTask := agent.advertiseAndRenewExecutorRoleT()
	jobExecutorTask := agent.watchForJobOffersT()
	watchNewLeaderTask := agent.watchForNewLeaderElectionT()

	for {
		select {
		case err := <-task.FirstError(
			agent.listenUICancelTask(), //ErrUserCanceled
			leaderTask,
			jobPublisherTask,
			executorTask,
			jobExecutorTask):

			agent.lastError = err
			return errorStateFn
		case <-watchNewLeaderTask.ErrorChan():
			return candidateStateFn
		}
	}
}
Example #2
0
func TestFindFirstError(t *testing.T) {

	tsk1 := task.NewDummy().RunEvery(time.Second * 1)
	tsk2 := task.NewDummy().RunEvery(time.Second * 1)

	// Stop one task after timeout
	go func() {
		timeout := time.NewTimer(time.Second * 2)
		<-timeout.C
		tsk1.Stop()
	}()

	firstErr := <-task.FirstError(tsk1, tsk2)
	if firstErr.Error() != task.ErrUserCanceled.Error() {
		t.Errorf("Expected to get an user cancelation error")
	}

}
Example #3
0
func supporterStateFn(agent *Agent) handleStateFn {
	agent.changeState("SUPPORTER_STATE")

	executorTask := agent.advertiseAndRenewExecutorRoleT()
	jobExecutorTask := agent.watchForJobOffersT()
	watchNewLeaderTask := agent.watchForNewLeaderElectionT()

	for {
		select {
		case err := <-task.FirstError(
			agent.listenUICancelTask(), //ErrUserCanceled
			executorTask,
			jobExecutorTask):

			agent.lastError = err
			return errorStateFn
		case <-watchNewLeaderTask.ErrorChan():
			return candidateStateFn

		}
	}
}