Documentation ¶
Overview ¶
Package tasks contains code to manage a task's lifecycle.
Index ¶
- func RegisterCleanupHandlers(crondisp *cron.Dispatcher, tqdisp *tq.Dispatcher)
- type Cancellation
- type LifecycleTasks
- type LifecycleTasksForTests
- func (lt *LifecycleTasksForTests) EnqueueBatchCancel(ctx context.Context, batch []string, killRunning bool, purpose string, ...) error
- func (lt *LifecycleTasksForTests) PeekTasks(queue string) []string
- func (lt *LifecycleTasksForTests) PopNTasks(qName string, n int) (res []string)
- func (lt *LifecycleTasksForTests) PopTask(queue string) string
- type LifecycleTasksViaTQ
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCleanupHandlers ¶
func RegisterCleanupHandlers(crondisp *cron.Dispatcher, tqdisp *tq.Dispatcher)
RegisterCleanupHandlers registers cron and TQ handlers that implement old task cleanup.
Types ¶
type Cancellation ¶
type Cancellation struct { TaskID string // TaskRequest and TaskResultSummary are required in RunInTxn. TaskRequest *model.TaskRequest TaskResultSummary *model.TaskResultSummary // Whether to kill the task if it has started running. KillRunning bool // ID of the bot the task should run on. Can only be specified if // KillRunning is true. BotID string // LifecycleTasks is used to emit TQ tasks related to Swarming task lifecycle. LifecycleTasks LifecycleTasks }
Cancellation contains information to cancel a task.
func (*Cancellation) Run ¶
Run cancels a task if possible.
Ensures that the associated TaskToRun is canceled (when PENDING) and updates the TaskResultSummary/TaskRunResult accordingly.
For PENDING tasks, the TaskResultSummary's state is immediately changed. For RUNNING tasks, the TaskRunResult.Killing bit is immediately set, but their state (in TaskRunResult and TaskResultSummary) is not changed yet.
Warning: ACL check must have been done before.
Returns * a bool for whether the task has started the cancellation process as requested, * a bool for whether the task was running when being canceled, * an err for errors to cancel the task.
func (*Cancellation) RunInTxn ¶
func (c *Cancellation) RunInTxn(ctx context.Context) (bool, error)
RunInTxn updates entities of the task to cancel and enqueues the cloud tasks to cancel its children and send notifications.
Mutates c.TaskResultSummary in place.
Must run in a transaction.
Returns * a bool for whether the task has started the cancellation process as requested, * an err for errors to cancel the task.
type LifecycleTasks ¶
type LifecycleTasks interface { EnqueueBatchCancel(ctx context.Context, batch []string, killRunning bool, purpose string, retries int32) error // contains filtered or unexported methods }
LifecycleTasks is used to emit TQ tasks related to Swarming task lifecycle.
type LifecycleTasksForTests ¶
type LifecycleTasksForTests struct {
// contains filtered or unexported fields
}
LifecycleTasksForTests mocks tq tasks for task lifecycle management, only used for tests.
func MockTQTasks ¶
func MockTQTasks() *LifecycleTasksForTests
MockTQTasks returns TestTQTasks with mocked tq functions for managing a task's lifecycle.
func (*LifecycleTasksForTests) EnqueueBatchCancel ¶
func (lt *LifecycleTasksForTests) EnqueueBatchCancel(ctx context.Context, batch []string, killRunning bool, purpose string, retries int32) error
EnqueueBatchCancel enqueues a tq task to cancel tasks in batch.
func (*LifecycleTasksForTests) PeekTasks ¶
func (lt *LifecycleTasksForTests) PeekTasks(queue string) []string
PeekTasks returns all the tasks in the queue without popping them.
func (*LifecycleTasksForTests) PopNTasks ¶
func (lt *LifecycleTasksForTests) PopNTasks(qName string, n int) (res []string)
PopNTasks pops n tasks from the queue.
If there are fewer than n tasks in the queue, just pop all of them.
func (*LifecycleTasksForTests) PopTask ¶
func (lt *LifecycleTasksForTests) PopTask(queue string) string
PopTask pops a task from the queue.
type LifecycleTasksViaTQ ¶
type LifecycleTasksViaTQ struct {
Dispatcher *tq.Dispatcher
}
func (*LifecycleTasksViaTQ) EnqueueBatchCancel ¶
func (l *LifecycleTasksViaTQ) EnqueueBatchCancel(ctx context.Context, batch []string, killRunning bool, purpose string, retries int32) error
EnqueueBatchCancel enqueues a tq task to cancel tasks in batch.
func (*LifecycleTasksViaTQ) RegisterTQTasks ¶
func (l *LifecycleTasksViaTQ) RegisterTQTasks()
RegisterTQTasks regusters TQ tasks for task lifecycle management.