tasks

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2025 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlanForUnassociatedOperations       = "_unassociated_"
	InstanceIDForUnassociatedOperations = "_unassociated_"
	PlanForSystemTasks                  = "_system_" // plan for system tasks e.g. garbage collection, prune, stats, etc.

	TaskPriorityStats          = 0
	TaskPriorityDefault        = 1 << 1 // default priority
	TaskPriorityForget         = 1 << 2
	TaskPriorityIndexSnapshots = 1 << 3
	TaskPriorityCheck          = 1 << 4 // check should always run after prune.
	TaskPriorityPrune          = 1 << 5
	TaskPriorityInteractive    = 1 << 6 // highest priority
)

Variables

View Source
var NeverScheduledTask = ScheduledTask{}

Functions

func FlowIDForSnapshotID

func FlowIDForSnapshotID(runner TaskRunner, repoGUID string, snapshotID string) (int64, error)

FlowIDForSnapshotID returns the flow ID associated with the backup task that created snapshot ID or 0 if not found.

Types

type BackupTask

type BackupTask struct {
	BaseTask
	// contains filtered or unexported fields
}

BackupTask is a scheduled backup operation.

func NewOneoffBackupTask

func NewOneoffBackupTask(repo *v1.Repo, plan *v1.Plan, at time.Time) *BackupTask

func NewScheduledBackupTask

func NewScheduledBackupTask(repo *v1.Repo, plan *v1.Plan) *BackupTask

func (*BackupTask) Next

func (t *BackupTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

func (*BackupTask) Run

func (t *BackupTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner) error

type BaseTask

type BaseTask struct {
	TaskType   string
	TaskName   string
	TaskPlanID string
	TaskRepo   *v1.Repo
}

func (BaseTask) Name

func (b BaseTask) Name() string

func (BaseTask) PlanID

func (b BaseTask) PlanID() string

func (BaseTask) Repo added in v1.7.0

func (b BaseTask) Repo() *v1.Repo

func (BaseTask) RepoID

func (b BaseTask) RepoID() string

func (BaseTask) Type added in v1.5.0

func (b BaseTask) Type() string

type CheckTask added in v1.1.0

type CheckTask struct {
	BaseTask
	// contains filtered or unexported fields
}

func (*CheckTask) Next added in v1.1.0

func (t *CheckTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

func (*CheckTask) Run added in v1.1.0

func (t *CheckTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner) error

type CollectGarbageTask

type CollectGarbageTask struct {
	BaseTask
	// contains filtered or unexported fields
}

func NewCollectGarbageTask

func NewCollectGarbageTask(logstore *logstore.LogStore) *CollectGarbageTask

func (*CollectGarbageTask) Next

func (t *CollectGarbageTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

func (*CollectGarbageTask) Run

type GenericOneoffTask

type GenericOneoffTask struct {
	OneoffTask
	Do func(ctx context.Context, st ScheduledTask, runner TaskRunner) error
}

func (*GenericOneoffTask) Run

type HookVars added in v1.3.0

type HookVars struct {
	Task          string                      // the name of the task that triggered the hook.
	Event         v1.Hook_Condition           // the event that triggered the hook.
	Repo          *v1.Repo                    // the v1.Repo that triggered the hook.
	Plan          *v1.Plan                    // the v1.Plan that triggered the hook.
	SnapshotId    string                      // the snapshot ID that triggered the hook.
	SnapshotStats *restic.BackupProgressEntry // the summary of the backup operation.
	CurTime       time.Time                   // the current time as time.Time
	Duration      time.Duration               // the duration of the operation that triggered the hook.
	Error         string                      // the error that caused the hook to run as a string.
}

HookVars is the set of variables that are available to a hook. Some of these are optional. NOTE: names of HookVars may change between versions of backrest. This is not a guaranteed stable API. when names change hooks will require updating.

func (HookVars) EventName added in v1.3.0

func (v HookVars) EventName(cond v1.Hook_Condition) string

func (HookVars) FormatDuration added in v1.3.0

func (v HookVars) FormatDuration(d time.Duration) string

func (HookVars) FormatSizeBytes added in v1.3.0

func (v HookVars) FormatSizeBytes(val any) string

func (HookVars) FormatTime added in v1.3.0

func (v HookVars) FormatTime(t time.Time) string

func (HookVars) IsError added in v1.3.0

func (v HookVars) IsError(cond v1.Hook_Condition) bool

func (HookVars) JsonMarshal added in v1.3.0

func (v HookVars) JsonMarshal(s any) string

func (HookVars) ShellEscape added in v1.3.0

func (v HookVars) ShellEscape(s string) string

func (HookVars) Summary added in v1.3.0

func (v HookVars) Summary() (string, error)

type OneoffTask

type OneoffTask struct {
	BaseTask
	RunAt       time.Time
	FlowID      int64 // the ID of the flow this task is associated with.
	DidSchedule bool
	ProtoOp     *v1.Operation // the prototype operation for this class of task.
}

func (*OneoffTask) Next

func (o *OneoffTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

type PruneTask

type PruneTask struct {
	BaseTask
	// contains filtered or unexported fields
}

func (*PruneTask) Next

func (t *PruneTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

func (*PruneTask) Run

func (t *PruneTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner) error

type RetryBackoffPolicy added in v1.5.0

type RetryBackoffPolicy = func(attempt int) time.Duration

type ScheduledTask

type ScheduledTask struct {
	Task  Task          // the task to run
	RunAt time.Time     // the time at which the task should be run.
	Op    *v1.Operation // operation associated with this execution of the task.
}

ScheduledTask is a task that is scheduled to run at a specific time.

func (ScheduledTask) Eq

func (s ScheduledTask) Eq(other ScheduledTask) bool

func (ScheduledTask) Less

func (s ScheduledTask) Less(other ScheduledTask) bool

type StatsTask

type StatsTask struct {
	BaseTask
	// contains filtered or unexported fields
}

func (*StatsTask) Next

func (t *StatsTask) Next(now time.Time, runner TaskRunner) (ScheduledTask, error)

func (*StatsTask) Run

func (t *StatsTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner) error

type Task

type Task interface {
	Name() string                                                       // human readable name for this task.
	Type() string                                                       // simple string 'type' for this 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.
	Repo() *v1.Repo                                                     // the repo this task is associated with.
}

Task is a task that can be scheduled to run at a specific time.

func NewCheckTask added in v1.1.0

func NewCheckTask(repo *v1.Repo, planID string, force bool) Task

func NewOneoffForgetSnapshotTask

func NewOneoffForgetSnapshotTask(repo *v1.Repo, planID string, flowID int64, at time.Time, snapshotID string) Task

func NewOneoffForgetTask

func NewOneoffForgetTask(repo *v1.Repo, planID string, flowID int64, at time.Time) Task

func NewOneoffIndexSnapshotsTask

func NewOneoffIndexSnapshotsTask(repo *v1.Repo, at time.Time) Task

func NewOneoffRestoreTask

func NewOneoffRestoreTask(repo *v1.Repo, planID string, flowID int64, at time.Time, snapshotID, path, target string) Task

func NewOneoffRunCommandTask added in v1.6.0

func NewOneoffRunCommandTask(repo *v1.Repo, planID string, flowID int64, at time.Time, command string) Task

func NewPruneTask

func NewPruneTask(repo *v1.Repo, planID string, force bool) Task

func NewStatsTask

func NewStatsTask(repo *v1.Repo, planID string, force bool) Task

type TaskCancelledError added in v1.5.0

type TaskCancelledError struct {
}

TaskCancelledError is returned when a task is cancelled.

func (TaskCancelledError) Error added in v1.5.0

func (e TaskCancelledError) Error() string

func (TaskCancelledError) Is added in v1.5.0

func (e TaskCancelledError) Is(err error) bool

type TaskExecutor added in v1.3.0

type TaskExecutor interface {
	RunTask(ctx context.Context, st ScheduledTask) error
}

type TaskRetryError added in v1.5.0

type TaskRetryError struct {
	Err     error
	Backoff RetryBackoffPolicy
}

TaskRetryError is returned when a task should be retried after a specified backoff duration.

func (TaskRetryError) Error added in v1.5.0

func (e TaskRetryError) Error() string

func (TaskRetryError) Unwrap added in v1.5.0

func (e TaskRetryError) Unwrap() error

type TaskRunner

type TaskRunner interface {
	// InstanceID returns the instance ID executing this task.
	InstanceID() string
	// GetOperation returns the operation with the given ID.
	GetOperation(id int64) (*v1.Operation, error)
	// CreateOperation creates the operation in storage and sets the operation ID in the task.
	CreateOperation(...*v1.Operation) error
	// UpdateOperation updates the operation in storage. It must be called after CreateOperation.
	UpdateOperation(...*v1.Operation) error
	// DeleteOperation deletes the operation from storage.
	DeleteOperation(...int64) error
	// QueryOperations queries the operation log.
	QueryOperations(oplog.Query, func(*v1.Operation) error) error
	// ExecuteHooks
	ExecuteHooks(ctx context.Context, events []v1.Hook_Condition, vars HookVars) error
	// GetRepo returns the repo with the given ID.
	GetRepo(repoID string) (*v1.Repo, error)
	// GetPlan returns the plan with the given ID.
	GetPlan(planID string) (*v1.Plan, error)
	// GetRepoOrchestrator returns the orchestrator for the repo with the given ID.
	GetRepoOrchestrator(repoID string) (*repo.RepoOrchestrator, error)
	// ScheduleTask schedules a task to run at a specific time.
	ScheduleTask(task Task, priority int) error
	// Config returns the current config.
	Config() *v1.Config
	// Logger returns the logger.
	Logger(ctx context.Context) *zap.Logger
	// LogrefWriter returns a writer that can be used to track streaming operation output.
	LogrefWriter() (id string, w io.WriteCloser, err error)
}

TaskRunner is an interface for running tasks. It is used by tasks to create operations and write logs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL