step

package
v0.0.0-...-c1401b0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

In many cases such as restoring backups, tasks can be quite complex and should/can be broken down into smaller steps

Step is an utility structure that allows breaking down tasks complete with persist support

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Step

type Step[T any] struct {
	State string

	// By default, steps of a lower index are ignored
	// Steps may however have an equal index in which case the step that is first in the array is first executed
	Index int

	// Exec will either return the task output which ends the task
	// or a task progress telling the new progress of the task
	// or an error to quickly abort the stepping
	//
	// After finishing the task
	Exec func(
		t *T,
		l *zap.Logger,
		state taskstate.TaskState,
		progstate taskstate.TaskProgressState,
		progress *taskstate.Progress,
	) (*types.TaskOutput, *taskstate.Progress, error)
}

type Stepper

type Stepper[T any] struct {
	// contains filtered or unexported fields
}

func NewStepper

func NewStepper[T any](steps ...Step[T]) *Stepper[T]

NewStepper creates a new stepper

func (*Stepper[T]) Exec

func (s *Stepper[T]) Exec(
	task *T,
	l *zap.Logger,
	state taskstate.TaskState,
	progstate taskstate.TaskProgressState,
) (*types.TaskOutput, error)

Exec executes all steps, skipping over steps with a lower index

func (*Stepper[T]) Step

func (s *Stepper[T]) Step(state string) (*Step[T], bool)

Step returns a step based on its state

func (*Stepper[T]) StepIndex

func (s *Stepper[T]) StepIndex(state string) int

StepPosition returns the index of a step

Jump to

Keyboard shortcuts

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