Documentation ¶
Overview ¶
Package tasks contains code to manage a task's lifecycle.
Index ¶
- Variables
- func RegisterCleanupHandlers(crondisp *cron.Dispatcher, tqdisp *tq.Dispatcher)
- type Cancellation
- type Creation
- 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 ¶
var ErrAlreadyExists = errors.New("task already exists")
ErrAlreadyExists is a special error to return when task ID collision happens.
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 Creation ¶
type Creation struct { // RequestID is used to make new task request idempotent. RequestID string // Request is the TaskRequest entity representing the new task. Request *model.TaskRequest // SecretBytes is the SecretBytes entity. SecretBytes *model.SecretBytes // BuildTask is the BuildTask entity. BuildTask *model.BuildTask // SwarmingProject is the Cloud project of the Swarming service, e.g. "chromium-swarm". SwarmingProject string // ServerVersion is the version of the executing binary. ServerVersion string // Config is a snapshot of the server configuration. Config *cfg.Config // LifecycleTasks is used to emit TQ tasks related to Swarming task lifecycle. LifecycleTasks LifecycleTasks }
Creation contains information to create a new task.
func (*Creation) Run ¶
Run creates and stores all the entities to create a new task.
The number of entities created is ~5: TaskRequest, TaskToRunShard and TaskResultSummary and (optionally) SecretBytes and BuildTask. They are in single entity group and saved in a single transaction. If c.RequestID is provided, a TaskRequestID may also be created if c.RequestID is being used the first time.
If task ID collision happens, a special error `ErrAlreadyExists` will be returned so the server could retry creating the entities.
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.