Example #1
0
func (s *ManagerSuite) SetUpTest(c *C) {
	s.busManager = event.NewBusManager()
	s.busManager.Start()
	s.store = model.NewStore(s.busManager)
	s.manager = dispatch.NewManager(s.busManager, s.store)
	s.team = s.store.Teams.Create(model.A{"Name": "James Bond"})
}
Example #2
0
func (s *DistributorSuite) TestFindTaskForTeammateWhenOne(c *C) {
	task := s.store.Tasks.Create(model.A{"Title": "Skyfall"}, s.team)
	queue := s.store.Queues.Create(model.A{"Name": "Daniel Craig"}, s.team)
	teammate := s.store.Teammates.Create(model.A{"Name": "007"}, s.team)
	s.store.Skills.Create(model.A{"Level": model.LevelHigh}, teammate, queue)
	manager := dispatch.NewManager(s.busManager, s.store)
	manager.QueueTask(queue, task)
	task2 := s.store.Tasks.Find(task.Uid())
	queue2 := s.store.Queues.Find(queue.Uid())
	c.Assert(task2.Status(), Equals, model.StatusQueued)
	c.Assert(task2.QueueUid(), Equals, queue.Uid())
	c.Assert(queue2.NextTaskUid(), DeepEquals, task.Uid())

	found := dispatch.FindTaskForTeammate(s.store, teammate)
	c.Assert(found, Not(IsNil))
	c.Assert(found.Uid(), Equals, task.Uid())
}
func (s *AcceptanceSuite) TestAssignsATaskToATeamMate(c *C) {
	aLittleBit := 100 * time.Millisecond

	// provisioning
	team := s.store.Teams.Create(model.A{"Name": "Jones Household"})
	manager := dispatch.NewManager(s.busManager, s.store)
	teammate := s.store.Teammates.Create(model.A{"Name": "Jack"}, team)
	queue := s.store.Queues.Create(model.A{"Name": "Duties"}, team)
	s.store.Skills.Create(model.A{"TeammateUid": teammate.Uid(),
		"QueueUid": queue.Uid()}, team)

	// keep track of events received
	var eventOne, eventTwo, eventThree event.Event
	go func() {
		incoming := s.busManager.SubscribeTo([]event.Kind{
			event.OfferTask, event.AcceptTask, event.CompleteTask,
		})
		eventOne = <-incoming
		fmt.Println("eventOne:", eventOne)
		eventTwo = <-incoming
		fmt.Println("eventTwo:", eventTwo)
		eventThree = <-incoming
		fmt.Println("eventThree:", eventThree)
	}()

	// create task and get have the teammate process it
	c.Assert(teammate.Status(), Equals, model.StatusSignedOut)
	teammate.SignIn()
	c.Assert(teammate.Status(), Equals, model.StatusOnBreak)

	task := s.store.Tasks.Create(model.A{"Title": "take out the trash"}, team)
	c.Assert(task.Status(), Equals, model.StatusCreated)
	manager.QueueTask(queue, task)
	c.Assert(task.Status(), Equals, model.StatusQueued)

	manager.MakeTeammateAvailable(teammate)
	task = task.Reload()
	c.Assert(teammate.Status(), Equals, model.StatusOffered)
	c.Assert(teammate.TaskUid(), DeepEquals, task.Uid())
	c.Assert(task.Status(), Equals, model.StatusOffered)

	time.Sleep(aLittleBit)
	c.Assert(eventOne.Kind, Equals, event.OfferTask)
	c.Assert(eventOne.Data[0], Equals, teammate.Uid())
	c.Assert(eventOne.Data[1], Equals, task.Uid())

	manager.AcceptTask(teammate, task)
	c.Assert(teammate.Status(), Equals, model.StatusBusy)
	c.Assert(teammate.TaskUid(), DeepEquals, task.Uid())
	c.Assert(task.Status(), Equals, model.StatusAssigned)
	c.Assert(queue.NextTaskUid(), DeepEquals, task.Uid())

	time.Sleep(aLittleBit)
	c.Assert(eventTwo.Kind, Equals, event.AcceptTask)
	c.Assert(eventTwo.Data[0], Equals, teammate.Uid())
	c.Assert(eventTwo.Data[1], Equals, task.Uid())

	manager.FinishTask(teammate, task)
	queue = queue.Reload()
	c.Assert(teammate.Status(), Equals, model.StatusWrappingUp)
	c.Assert(teammate.TaskUid(), Equals, "")
	c.Assert(task.Status(), Equals, model.StatusCompleted)
	c.Assert(queue.NextTaskUid(), DeepEquals, "")

	time.Sleep(aLittleBit)
	c.Assert(eventThree.Kind, Equals, event.CompleteTask)
	c.Assert(eventThree.Data[0], Equals, teammate.Uid())
	c.Assert(eventThree.Data[1], Equals, task.Uid())

	teammate.StartOtherWork()
	c.Assert(teammate.Status(), Equals, model.StatusOtherWork)

	teammate.GoOnBreak()
	c.Assert(teammate.Status(), Equals, model.StatusOnBreak)

	teammate.SignOut()
	c.Assert(teammate.Status(), Equals, model.StatusSignedOut)
}