task

package
v0.0.0-...-ac21e34 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChildAlreadyAdded = errors.New("child already added")

ErrChildAlreadyAdded error on adding already added child

View Source
var ErrNotChild = errors.New("adding non required child")

ErrNotChild error on adding a child task that not requires the task

Functions

func Do

func Do(ctx context.Context, cancelFunc context.CancelFunc, task *Task, storage Storage) error

Do executes task

Types

type DoFunc

type DoFunc func(ctx context.Context, payload interface{}) (interface{}, error)

DoFunc is task payload processing function. If DoFunc returns not nil value and there are no error the value will be saved in context as value with task.ID as key.

type ID

type ID string

ID is human readable unique per graph task identifier

type Result

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

Result describes task execution result

type Status

type Status string

Status is task status

const (
	// StatusNew status of new task
	StatusNew Status = "NEW"
	// StatusWaiting status of task waiting for required tasks completion
	StatusWaiting Status = "WAITING"
	// StatusRunning status of executing task
	StatusRunning Status = "RUNNING"
	// StatusReady status of successfully executed task
	StatusReady Status = "READY"
	// StatusCancelled status of cancelled task
	StatusCancelled Status = "CANCELLED"
	// StatusError status of task executed with error
	StatusError Status = "ERROR"
)

type Storage

type Storage interface {
	Save(task *Task) error
	Load(uuid uuid.UUID) (*Task, error)
}

Storage defines storage interface

type Task

type Task struct {
	sync.Mutex
	// UUID is storage specific identifier
	UUID uuid.UUID
	// ID is human readable unique per graph task identifier
	ID ID
	// Status is task status
	Status Status
	// Requires is map of tasks required for the task execution
	Requires map[ID]bool
	// Payload is task payload
	Payload interface{}

	// DoResult is result of task execution
	DoResult []byte
	// DoError is error of task execution
	DoError error

	// UndoResult is result of task revert
	UndoResult []byte
	// UndoError is error of task revert
	UndoError error
	// RequiredFor is map of tasks requires the task execution
	RequiredFor map[ID]bool
	// contains filtered or unexported fields
}

Task describes task structure

func NewTask

func NewTask(id ID, requires []ID, payload interface{}, doFunc DoFunc, undoFunc DoFunc) *Task

NewTask creates new task

func (*Task) AddChild

func (t *Task) AddChild(child *Task) error

AddChild adds child task.

Jump to

Keyboard shortcuts

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