
Worker and Manager implementation of the "may-I-kee-running" protocol. While running tasks, the Worker will ask the Manager periodically whether it's still allowed to keep running that task. This allows the Manager to abort commands on Workers when: - the Worker should go to another state (typically 'asleep' or 'shutdown'), - the task changed status from 'active' to something non-runnable (typically 'canceled' when the job as a whole is canceled). - the task has been assigned to a different Worker. This can happen when a Worker loses its connection to its Manager, resulting in a task timeout (not yet implemented) after which the task can be assigned to another Worker. If then the connectivity is restored, the first Worker should abort (last-assigned Worker wins).
27 lines
860 B
Go
27 lines
860 B
Go
package task_state_machine
|
|
|
|
import "git.blender.org/flamenco/pkg/api"
|
|
|
|
var (
|
|
// Task statuses that always get requeued when the job is requeued.
|
|
nonCompletedStatuses = []api.TaskStatus{
|
|
api.TaskStatusCanceled,
|
|
api.TaskStatusFailed,
|
|
api.TaskStatusPaused,
|
|
api.TaskStatusSoftFailed,
|
|
}
|
|
|
|
// Workers are allowed to keep running tasks when they are in this status.
|
|
// 'queued', 'claimed-by-manager', and 'soft-failed' aren't considered runnable,
|
|
// as those statuses indicate the task wasn't assigned to a Worker by the scheduler.
|
|
runnableStatuses = map[api.TaskStatus]bool{
|
|
api.TaskStatusActive: true,
|
|
}
|
|
)
|
|
|
|
// IsRunnableTaskStatus returns whether the given status is considered "runnable".
|
|
// In other words, workers are allowed to keep running such tasks.
|
|
func IsRunnableTaskStatus(status api.TaskStatus) bool {
|
|
return runnableStatuses[status]
|
|
}
|