mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 16:55:39 +00:00
feat: unified scheduling model (#282)
This commit is contained in:
@@ -15,6 +15,7 @@ var NeverScheduledTask = ScheduledTask{}
|
||||
|
||||
const (
|
||||
PlanForUnassociatedOperations = "_unassociated_"
|
||||
PlanForSystemTasks = "_system_" // plan for system tasks e.g. garbage collection, prune, stats, etc.
|
||||
|
||||
TaskPriorityStats = -1
|
||||
TaskPriorityDefault = 0
|
||||
@@ -67,7 +68,7 @@ func (s ScheduledTask) Less(other ScheduledTask) bool {
|
||||
// Task is a task that can be scheduled to run at a specific time.
|
||||
type Task interface {
|
||||
Name() string // human readable name for this task.
|
||||
Next(now time.Time, runner TaskRunner) ScheduledTask // returns the next scheduled task.
|
||||
Next(now time.Time, runner TaskRunner) (ScheduledTask, error) // returns the next scheduled task.
|
||||
Run(ctx context.Context, st ScheduledTask, runner TaskRunner) error // run the task.
|
||||
PlanID() string // the ID of the plan this task is associated with.
|
||||
RepoID() string // the ID of the repo this task is associated with.
|
||||
@@ -99,9 +100,9 @@ type OneoffTask struct {
|
||||
ProtoOp *v1.Operation // the prototype operation for this class of task.
|
||||
}
|
||||
|
||||
func (o *OneoffTask) Next(now time.Time, runner TaskRunner) ScheduledTask {
|
||||
func (o *OneoffTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error) {
|
||||
if o.DidSchedule {
|
||||
return NeverScheduledTask
|
||||
return NeverScheduledTask, nil
|
||||
}
|
||||
o.DidSchedule = true
|
||||
|
||||
@@ -118,7 +119,7 @@ func (o *OneoffTask) Next(now time.Time, runner TaskRunner) ScheduledTask {
|
||||
return ScheduledTask{
|
||||
RunAt: o.RunAt,
|
||||
Op: op,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
type GenericOneoffTask struct {
|
||||
|
||||
Reference in New Issue
Block a user