// Poll polls the task list for a task. If there is no task available, nil is
// returned. If an error is encountered, no task is returned.
194997
func (p *DecisionTaskPoller) Poll() (*PollForDecisionTaskResponse, error) {
	resp, err := p.client.PollForDecisionTask(PollForDecisionTaskRequest{
		Domain:       p.Domain,
		Identity:     p.Identity,
		ReverseOrder: true,
		TaskList:     TaskList{Name: p.TaskList},
	})
	if err != nil {
		log.Printf("component=DecisionTaskPoller at=error error=%s", err.Error())
		return nil, err
	}
	if resp.TaskToken != "" {
		log.Printf("component=DecisionTaskPoller at=decision-task-recieved workflow=%s", resp.WorkflowType.Name)
		p.logTaskLatency(resp)
		return resp, nil
	}
	log.Println("component=DecisionTaskPoller at=decision-task-empty-response")
	return nil, nil
}
943712
func taskReadyForNetworkVote(t *api.Task, s *api.Service, nc *networkContext) bool {
	// Task is ready for vote if the following is true:
	//
	// Task has no network attached or networks attached but all
	// of them allocated AND Task's service has no endpoint or
	// network configured or service endpoints have been
	// allocated.
	return (len(t.Networks) == 0 || nc.nwkAllocator.IsTaskAllocated(t)) &&
		(s == nil || nc.nwkAllocator.IsServiceAllocated(s))
}
1209665
func (w *CeleryWorker) RunTask(message *TaskMessage) (*ResultMessage, error) {

	// get task
	task := w.GetTask(message.Task)
	if task == nil {
		return nil, fmt.Errorf("task %s is not registered", message.Task)
	}

	// convert to task interface
	taskInterface, ok := task.(CeleryTask)
	if ok {
		if err := taskInterface.ParseKwargs(message.Kwargs); err != nil {
			return nil, err
		}
		val, err := taskInterface.RunTask()
		if err != nil {
			return nil, err
		}
		return getResultMessage(val), err
	}

	// use reflection to execute function ptr
	taskFunc := reflect.ValueOf(task)
	return runTaskFunc(&taskFunc, message)
}
1180778
func (c *Cluster) GetTask(input string) (types.Task, error) {
	var task *swarmapi.Task
	if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
		t, err := getTask(ctx, state.controlClient, input)
		if err != nil {
			return err
		}
		task = t
		return nil
	}); err != nil {
		return types.Task{}, err
	}
	return convert.TaskFromGRPC(*task)
}
216946
func (c *TasksListCall) Sort(sort string) *TasksListCall {
	c.urlParams_.Set("sort", sort)
	return c
}
779034
func (t *taskCollection) Get(id string) *task {
	t.Lock()
	defer t.Unlock()

	if t, ok := t.table[id]; ok {
		return t
	}
	return nil
}
946784
func (_m *APIClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
	ret := _m.Called(ctx, options)

	var r0 []swarm.Task
	if rf, ok := ret.Get(0).(func(context.Context, types.TaskListOptions) []swarm.Task); ok {
		r0 = rf(ctx, options)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]swarm.Task)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, types.TaskListOptions) error); ok {
		r1 = rf(ctx, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
819588
func (c *TasksRequestsCall) Sort(sort string) *TasksRequestsCall {
	c.urlParams_.Set("sort", sort)
	return c
}
761231
func (i *Index) WaitTask(taskID int) error {
	return waitWithRetry(func() (bool, error) {
		res, err := i.GetStatus(taskID)
		if err != nil {
			return true, err
		}
		if res.Status == "published" {
			return true, nil
		}
		return false, nil
	})
}
485472
func (tp *TransferPoller) Poll() error {
	tp.syncTimer.Pause()
	err := tp.pollTransfers()
	tp.syncTimer.Resume()
	return err
}
367314
func TaskWaitC(ctx types.Context, taskID int) <-chan int {
	return getTaskService(ctx).TaskWaitC(taskID)
}
134818
func (m *MockServiceAPIClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
	ret := m.ctrl.Call(m, "TaskList", ctx, options)
	ret0, _ := ret[0].([]swarm.Task)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
624374
func pollParent(t time.Duration) {
	for initial := os.Getppid(); initial == os.Getppid(); time.Sleep(t) {
	}
}
843257
func Task() (c *TaskController) {
	return &TaskController{
		List:      taskList,
		Detail:    taskDetail,
		Raw:       taskRaw,
		Logs:      taskLogs,
		FetchLogs: taskFetchLogs,
	}
}
281328
func (*CallingGoroutineDispatcher) DispatchTask(task *swf.PollForDecisionTaskOutput, handler func(*swf.PollForDecisionTaskOutput)) {
	handler(task)
}
23194
func (c *Client) GetTasks() ([]Task, error) {
	r := c.NewRequest("GET", "/tasks")
	resp, err := c.DoRequest(r)

	if err != nil {
		log.Printf("Error requesting tasks  %v", err)
		return nil, err
	}

	defer resp.Body.Close()

	resBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Printf("Error reading tasks request %v", resBody)
		return nil, err
	}
	tasks := []Task{}
	err = json.Unmarshal(resBody, &tasks)
	if err != nil {
		log.Printf("Error unmarshaling tasks %v", err)
	}
	return tasks, err
}
1147040
func taskWillNeverRun(task *api.Task) bool {
	return task.Status.State < api.TaskStateAssigned && task.DesiredState > api.TaskStateRunning
}