orchestrator

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskPriorityDefault = iota
	TaskPriorityIndexSnapshots
	TaskPriorityPrune
	TaskPriorityForget
	TaskPriorityInteractive // highest priority (add other priorities to this value for offsets)
)

Variables

View Source
var ErrPlanNotFound = errors.New("plan not found")
View Source
var ErrRepoInitializationFailed = errors.New("repo initialization failed")
View Source
var ErrRepoNotFound = errors.New("repo not found")

Functions

func WithOperation

func WithOperation(oplog *oplog.OpLog, op *v1.Operation, do func() error) error

WithOperation is a utility that creates an operation to track the function's execution. timestamps are automatically added and the status is automatically updated if an error occurs.

Types

type BackupTask

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

BackupTask is a scheduled backup operation.

func NewOneofBackupTask

func NewOneofBackupTask(orchestrator *Orchestrator, plan *v1.Plan, at time.Time) *BackupTask

func NewScheduledBackupTask

func NewScheduledBackupTask(orchestrator *Orchestrator, plan *v1.Plan) (*BackupTask, error)

func (*BackupTask) Name

func (t *BackupTask) Name() string

func (*BackupTask) Next

func (t *BackupTask) Next(now time.Time) *time.Time

func (*BackupTask) Run

func (t *BackupTask) Run(ctx context.Context) error

type CollectGarbageTask

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

func (*CollectGarbageTask) Cancel

func (t *CollectGarbageTask) Cancel(withStatus v1.OperationStatus) error

func (*CollectGarbageTask) Name

func (t *CollectGarbageTask) Name() string

func (*CollectGarbageTask) Next

func (t *CollectGarbageTask) Next(now time.Time) *time.Time

func (*CollectGarbageTask) OperationId

func (t *CollectGarbageTask) OperationId() int64

func (*CollectGarbageTask) Run

type ForgetTask

type ForgetTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

ForgetTask tracks a forget operation.

func NewOneofForgetTask

func NewOneofForgetTask(orchestrator *Orchestrator, plan *v1.Plan, linkSnapshot string, at time.Time) *ForgetTask

func (*ForgetTask) Name

func (t *ForgetTask) Name() string

func (*ForgetTask) Next

func (t *ForgetTask) Next(now time.Time) *time.Time

func (*ForgetTask) Run

func (t *ForgetTask) Run(ctx context.Context) error

type IndexSnapshotsTask

type IndexSnapshotsTask struct {
	// contains filtered or unexported fields
}

IndexSnapshotsTask tracks a forget operation.

func NewOneofIndexSnapshotsTask

func NewOneofIndexSnapshotsTask(orchestrator *Orchestrator, plan *v1.Plan, at time.Time) *IndexSnapshotsTask

func (*IndexSnapshotsTask) Cancel

func (t *IndexSnapshotsTask) Cancel(withStatus v1.OperationStatus) error

func (*IndexSnapshotsTask) Name

func (t *IndexSnapshotsTask) Name() string

func (*IndexSnapshotsTask) Next

func (t *IndexSnapshotsTask) Next(now time.Time) *time.Time

func (*IndexSnapshotsTask) OperationId

func (t *IndexSnapshotsTask) OperationId() int64

func (*IndexSnapshotsTask) Run

type Orchestrator

type Orchestrator struct {
	OpLog *oplog.OpLog
	// contains filtered or unexported fields
}

Orchestrator is responsible for managing repos and backups.

func NewOrchestrator

func NewOrchestrator(resticBin string, cfg *v1.Config, oplog *oplog.OpLog) (*Orchestrator, error)

func (*Orchestrator) ApplyConfig

func (o *Orchestrator) ApplyConfig(cfg *v1.Config) error

func (*Orchestrator) CancelOperation

func (o *Orchestrator) CancelOperation(operationId int64, status v1.OperationStatus) error

func (*Orchestrator) GetPlan

func (o *Orchestrator) GetPlan(planId string) (*v1.Plan, error)

func (*Orchestrator) GetRepo

func (o *Orchestrator) GetRepo(repoId string) (repo *RepoOrchestrator, err error)

func (*Orchestrator) Run

func (o *Orchestrator) Run(mainCtx context.Context)

Run is the main orchestration loop. Cancel the context to stop the loop.

func (*Orchestrator) ScheduleTask

func (o *Orchestrator) ScheduleTask(t Task, priority int)

type PruneTask

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

PruneTask tracks a forget operation.

func NewOneofPruneTask

func NewOneofPruneTask(orchestrator *Orchestrator, plan *v1.Plan, linkSnapshot string, at time.Time, force bool) *PruneTask

func (*PruneTask) Name

func (t *PruneTask) Name() string

func (*PruneTask) Next

func (t *PruneTask) Next(now time.Time) *time.Time

func (*PruneTask) Run

func (t *PruneTask) Run(ctx context.Context) error

type RepoOrchestrator

type RepoOrchestrator struct {
	// contains filtered or unexported fields
}

RepoOrchestrator is responsible for managing a single repo.

func (*RepoOrchestrator) Backup

func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCallback func(event *restic.BackupProgressEntry)) (*restic.BackupProgressEntry, error)

func (*RepoOrchestrator) Forget

func (r *RepoOrchestrator) Forget(ctx context.Context, plan *v1.Plan) ([]*v1.ResticSnapshot, error)

func (*RepoOrchestrator) ListSnapshotFiles

func (r *RepoOrchestrator) ListSnapshotFiles(ctx context.Context, snapshotId string, path string) ([]*v1.LsEntry, error)

func (*RepoOrchestrator) Prune

func (r *RepoOrchestrator) Prune(ctx context.Context, output io.Writer) error

func (*RepoOrchestrator) Restore

func (r *RepoOrchestrator) Restore(ctx context.Context, snapshotId string, path string, target string, progressCallback func(event *v1.RestoreProgressEntry)) (*v1.RestoreProgressEntry, error)

func (*RepoOrchestrator) Snapshots

func (r *RepoOrchestrator) Snapshots(ctx context.Context) ([]*restic.Snapshot, error)

func (*RepoOrchestrator) SnapshotsForPlan

func (r *RepoOrchestrator) SnapshotsForPlan(ctx context.Context, plan *v1.Plan) ([]*restic.Snapshot, error)

func (*RepoOrchestrator) Unlock

func (r *RepoOrchestrator) Unlock(ctx context.Context) error

type RestoreTask

type RestoreTask struct {
	TaskWithOperation
	// contains filtered or unexported fields
}

RestoreTask tracks a forget operation.

func NewOneofRestoreTask

func NewOneofRestoreTask(orchestrator *Orchestrator, opts RestoreTaskOpts, at time.Time) *RestoreTask

func (*RestoreTask) Name

func (t *RestoreTask) Name() string

func (*RestoreTask) Next

func (t *RestoreTask) Next(now time.Time) *time.Time

func (*RestoreTask) Run

func (t *RestoreTask) Run(ctx context.Context) error

type RestoreTaskOpts

type RestoreTaskOpts struct {
	PlanId     string
	RepoId     string
	SnapshotId string
	Path       string
	Target     string
}

type Task

type Task interface {
	Name() string                               // huamn readable name for this task.
	Next(now time.Time) *time.Time              // when this task would like to be run.
	Run(ctx context.Context) error              // run the task.
	Cancel(withStatus v1.OperationStatus) error // informat the task that it's scheduled execution will be skipped (either STATUS_USER_CANCELLED or STATUS_SYSTEM_CANCELLED).
	OperationId() int64                         // the id of the operation associated with this task (if any).
}

type TaskWithOperation

type TaskWithOperation struct {
	// contains filtered or unexported fields
}

func (*TaskWithOperation) Cancel

func (t *TaskWithOperation) Cancel(withStatus v1.OperationStatus) error

Cancel marks a task as cancelled. Note that, unintuitively, it is actually an error to call cancel on a running task.

func (*TaskWithOperation) OperationId

func (t *TaskWithOperation) OperationId() int64

Jump to

Keyboard shortcuts

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