Example #1
0
/*
 * FindTaskForTeammate
 */
func FindTaskForTeammate(store *model.Store, teammate *model.Teammate) *model.Task {
	teamUid := teammate.TeamUid()
	queuesWithTasks := store.Queues.Select(func(item interface{}) bool {
		queue := item.(*model.Queue)
		// TODO: select only queues with a task waiting
		return queue.TeamUid() == teamUid && queue.NextTaskUid() != ""
	})
	if len(queuesWithTasks) == 0 {
		return nil
	}
	taskUid := queuesWithTasks[0].NextTaskUid()
	task := store.Tasks.Find(taskUid)
	return task
}
Example #2
0
func (manager Manager) FinishTask(teammate *model.Teammate, task *model.Task) bool {
	if task.TeammateUid() != teammate.Uid() ||
		teammate.TaskUid() != task.Uid() {
		return false
	}
	if queue := manager.store.Queues.Find(task.QueueUid()); queue != nil {
		queue.DelTask(task.Uid())
	}
	if !task.Complete() {
		return false
	}
	teammate.FinishTask(task.Uid())
	manager.busManager.PublishEvent(event.CompleteTask, teammate.Identity,
		[]interface{}{teammate.Uid(), task.Uid()})
	return true
}
Example #3
0
func (manager Manager) AcceptTask(teammate *model.Teammate, task *model.Task) bool {
	if !task.Assign(teammate.Uid()) {
		return false
	}
	if teammate.AcceptTask(task.Uid()) {
		manager.busManager.PublishEvent(event.AcceptTask, teammate.Identity,
			[]interface{}{teammate.Uid(), task.Uid()})
		return true
	}
	task.Requeue()
	return false
}
Example #4
0
func (manager Manager) MakeTeammateAvailable(teammate *model.Teammate) bool {
	if !teammate.MakeAvailable() {
		return false
	}
	manager.busManager.PublishEvent(event.TeammateAvailable,
		teammate.Identity, []interface{}{})
	if task := FindTaskForTeammate(manager.store, teammate); task != nil {
		// for now we just try offering this task: if it doesn't work we give up
		if !task.Offer(teammate.Uid()) {
			return true
		}
		if teammate.OfferTask(task.Uid()) {
			manager.busManager.PublishEvent(event.OfferTask, teammate.Identity,
				[]interface{}{teammate.Uid(), task.Uid()})
		} else {
			task.Requeue()
		}
	}
	return true
}