// RemoveTask removes a task from the schedule tasks given a task id. It's through an HTTP DELETE call.
// The removed task id returns if it succeeds. Otherwise, an error is returned.
337874
func (c *Client) RemoveTask(id string) *RemoveTasksResult {
	resp, err := c.do("DELETE", fmt.Sprintf("/tasks/%v", id), ContentTypeJSON)
	if err != nil {
		return &RemoveTasksResult{Err: err}
	}

	switch resp.Meta.Type {
	case rbody.ScheduledTaskRemovedType:
		// Success
		return &RemoveTasksResult{resp.Body.(*rbody.ScheduledTaskRemoved), nil}
	case rbody.ErrorType:
		return &RemoveTasksResult{Err: resp.Body.(*rbody.Error)}
	default:
		return &RemoveTasksResult{Err: ErrAPIResponseMetaType}
	}
}
1192905
func (r *Runtime) Delete(ctx context.Context, id string) {
	r.tasks.Delete(ctx, id)
}
1022145
func (s *scheduler) StopTask(id string) []serror.SnapError {
	return s.stopTask(id, "user")
}
1164511
func (c *Client) EnableTask(id string) *EnableTaskResult {
	resp, err := c.do("PUT", fmt.Sprintf("/tasks/%v/enable", id), ContentTypeJSON)
	if err != nil {
		return &EnableTaskResult{Err: err}
	}

	switch resp.Meta.Type {
	case rbody.ScheduledTaskEnabledType:
		return &EnableTaskResult{resp.Body.(*rbody.ScheduledTaskEnabled), nil}
	case rbody.ErrorType:
		return &EnableTaskResult{Err: resp.Body.(*rbody.Error)}
	default:
		return &EnableTaskResult{Err: ErrAPIResponseMetaType}
	}
}
937220
func (s *service) getTask(tid string) (shimTask, error) {
	raw := s.taskOrPod.Load()
	if raw == nil {
		return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
	}
	if s.isSandbox {
		p := raw.(shimPod)
		return p.GetTask(tid)
	}
	// When its not a sandbox only the init task is a valid id.
	if s.tid != tid {
		return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
	}
	return raw.(shimTask), nil
}
616186
func (tr *TaskRunner) killTask(handle *DriverHandle) error {
	// Cap the number of times we attempt to kill the task.
	var err error
	for i := 0; i < killFailureLimit; i++ {
		if err = handle.Kill(); err != nil {
			if err == drivers.ErrTaskNotFound {
				tr.logger.Warn("couldn't find task to kill", "task_id", handle.ID())
				return nil
			}
			// Calculate the new backoff
			backoff := (1 << (2 * uint64(i))) * killBackoffBaseline
			if backoff > killBackoffLimit {
				backoff = killBackoffLimit
			}

			tr.logger.Error("failed to kill task", "backoff", backoff, "error", err)
			time.Sleep(backoff)
		} else {
			// Kill was successful
			return nil
		}
	}
	return err
}
708249
func NewRemoveTask(cluster *Cluster, packageName string) *RemoveTask {
	return &RemoveTask{
		baseTask:    newTask(cluster),
		packageName: packageName,
	}
}
1364622
func (na *cnmNetworkAllocator) DeallocateTask(t *api.Task) error {
	delete(na.tasks, t.ID)
	return na.releaseEndpoints(t.Networks)
}
204588
func (l *lru) Remove(aps []AvailablePlugin, taskID string) (AvailablePlugin, error) {
	ap, err := l.Select(aps, taskID)
	if err != nil {
		return nil, err
	}
	return ap, nil
}
775507
func (w *CeleryWorker) GetTask(name string) interface{} {
	w.taskLock.RLock()
	task, ok := w.registeredTasks[name]
	if !ok {
		w.taskLock.RUnlock()
		return nil
	}
	w.taskLock.RUnlock()
	return task
}
383182
func (s *BoltStateDB) DeleteTaskBucket(allocID, taskName string) error {
	return s.db.Update(func(tx *boltdd.Tx) error {
		// Retrieve the root allocations bucket
		allocations := tx.Bucket(allocationsBucketName)
		if allocations == nil {
			return nil
		}

		// Retrieve the specific allocations bucket
		alloc := allocations.Bucket([]byte(allocID))
		if alloc == nil {
			return nil
		}

		// Check if the bucket exists
		key := taskBucketName(taskName)
		return alloc.DeleteBucket(key)
	})
}
1148451
func (_m *Marathon) KillTask(taskID string, opts *marathon.KillTaskOpts) (*marathon.Task, error) {
	ret := _m.Called(taskID, opts)

	var r0 *marathon.Task
	if rf, ok := ret.Get(0).(func(string, *marathon.KillTaskOpts) *marathon.Task); ok {
		r0 = rf(taskID, opts)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*marathon.Task)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string, *marathon.KillTaskOpts) error); ok {
		r1 = rf(taskID, opts)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
362605
func (s *StopTaskOutput) SetTask(v *Task) *StopTaskOutput {
	s.Task = v
	return s
}
1293935
func (d *TaskControlService) SetTask(task *influxdb.Task) {
	d.mu.Lock()
	defer d.mu.Unlock()

	d.tasks[task.ID] = task
}
108871
func (s *scheduler) StartTask(id string) []serror.SnapError {
	return s.startTask(id, "user")
}
404467
func (s *Service) UpdateTask(ctx context.Context, id influxdb.ID, upd influxdb.TaskUpdate) (*influxdb.Task, error) {
	var t *influxdb.Task
	err := s.kv.Update(ctx, func(tx Tx) error {
		task, err := s.updateTask(ctx, tx, id, upd)
		if err != nil {
			return err
		}
		t = task
		return nil
	})
	if err != nil {
		return nil, err
	}

	return t, nil
}
249594
func (_m *Marathon) KillTasks(taskIDs []string, opts *marathon.KillTaskOpts) error {
	ret := _m.Called(taskIDs, opts)

	var r0 error
	if rf, ok := ret.Get(0).(func([]string, *marathon.KillTaskOpts) error); ok {
		r0 = rf(taskIDs, opts)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}