task

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRequeueAfter = 5 * time.Second
)

Variables

View Source
var ErrWait = errors.New("wait until some changes are watched")

Functions

func IsWaitError

func IsWaitError(err error) bool

Types

type AggregateResult

type AggregateResult interface {
	Result
	// contains filtered or unexported methods
}

type CondFunc

type CondFunc func() bool

func (CondFunc) Satisfy

func (f CondFunc) Satisfy() bool

type Condition

type Condition interface {
	Satisfy() bool
}

type NamedResult

type NamedResult interface {
	Result
	// contains filtered or unexported methods
}

type Result

type Result interface {
	Status() Status
	RequeueAfter() time.Duration
	Message() string
}

Result defines the result of a task

func RunTask

func RunTask(ctx context.Context, t Task) (Result, bool)

type Status

type Status int
const (
	// task is complete and will not be requeue
	SComplete Status = iota
	// task is unexpectedly failed, runner will be interrupted
	SFail
	// some preconditions are not met, wait update events to trigger next run
	SWait
	// retry tasks after specified duration
	SRetry
)

func (Status) String

func (s Status) String() string

type SyncFunc

type SyncFunc func(ctx context.Context) Result

func (SyncFunc) Sync

func (f SyncFunc) Sync(ctx context.Context) Result

type Syncer

type Syncer interface {
	Sync(ctx context.Context) Result
}

Syncer defines an action to sync actual states to desired.

type Task

type Task interface {
	// contains filtered or unexported methods
}

Task is a Syncer wrapper, which can be orchestrated using control structures such as if and break for conditional logic and flow control. Task can only be implemented by this package and users should implement the Syncer interface and wrap Syncers as Tasks

func Block

func Block(tasks ...Task) Task

func Break

func Break(tasks ...Task) Task

func If

func If(cond Condition, tasks ...Task) Task

func IfBreak

func IfBreak(cond Condition, tasks ...Task) Task

func IfNot

func IfNot(cond Condition, tasks ...Task) Task

func NameTaskFunc

func NameTaskFunc(name string, f SyncFunc) Task

type TaskReporter

type TaskReporter interface {
	AddResult(r Result)
	Summary() string
}

func NewTableTaskReporter

func NewTableTaskReporter(id string) TaskReporter

type TaskRunner

type TaskRunner interface {
	Run(ctx context.Context) (ctrl.Result, error)
}

TaskRunner is an executor to run a series of tasks sequentially

func NewTaskRunner

func NewTaskRunner(reporter TaskReporter, ts ...Task) TaskRunner

NewTaskRunner creates a TaskRunner with the given reporter and tasks. There are four status of tasks - Complete: means this task is complete and all is expected - Failed: means an err occurred - Retry: means this task need to wait an interval and retry - Wait: means this task will wait for next event trigger And three results of reconiling 1. A task is failed, return err and wait with backoff 2. Some tasks need retry and max interval is 0, requeue directly with backoff 3. Some tasks need retry and max interval is higher than MinRequeueAfter, requeue after the max interval without backoff 4. All tasks are complete or wait, the key will not be re-added

type WithMessage

type WithMessage interface {
	With(format string, args ...any) Result
}

WithMessage defines an interface to set message into task result

func Complete

func Complete() WithMessage

Complete means complete the current task and run the next one

func Fail

func Fail() WithMessage

Fail means fail the current task and skip all next tasks

func Retry

func Retry(dur time.Duration) WithMessage

Retry means continue all next tasks and retry after dur

func Wait

func Wait() WithMessage

Wait means continue all next tasks and wait until next event triggers task run

Jump to

Keyboard shortcuts

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