runner

package
v0.0.0-...-f856fe1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StateName = map[State]string{
		0: "PENDING",
		1: "RUNNING",
		2: "SUCCEEDED",
		3: "CANCELING",
		4: "CANCELED",
		5: "FAILED",
	}
	StateValue = map[string]State{
		"PENDING":   0,
		"RUNNING":   1,
		"SUCCEEDED": 2,
		"CANCELING": 3,
		"CANCELED":  4,
		"FAILED":    5,
	}
)

Functions

func NewFuncOptionWithArg

func NewFuncOptionWithArg[T any](opt FuncOptionWithArg[T], arg T) *funcOptionWithArg[T]

func Register

func Register(typ string, creator FuncOptionCreator)

func Verify

func Verify(typ string, option string) error

func WithDryRun

func WithDryRun(dryRun bool) taskOption

func WithID

func WithID(id string) taskOption

func WithLogger

func WithLogger(logger Logger) taskOption

func WithName

func WithName(name string) taskOption

Types

type Cache

type Cache[K comparable, V any] interface {
	Load(K) (V, bool)
	Store(K, V)
	Delete(K)
	Reset()
	Range(func(K, V) bool)
	Len() int
}

func NewCache

func NewCache[K comparable, V any]() Cache[K, V]

type FuncOption

type FuncOption interface {
	String() string
	Execute(Task) error
}

func NewFuncOption

func NewFuncOption(typ string, option string) (FuncOption, error)

type FuncOptionCreator

type FuncOptionCreator func() FuncOption

type FuncOptionWithArg

type FuncOptionWithArg[T any] interface {
	String() string
	Execute(Task, T) error
}

type Logger

type Logger interface {
	Info(...interface{})
	Infof(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
}

func NewLogger

func NewLogger(out io.Writer) Logger

type Option

type Option interface {
	NewTask() Task
}

type Runner

type Runner interface {
	Context() context.Context
	Execute(Task)
	Submit(string, func(Task) error, ...taskOption) Task
	SubmitByOption(FuncOption, ...taskOption) Task
	SubmitByTask(Task) Task
	Get(string) (Task, bool)
	GetAll(...func(Task) bool) []Task
	Retry(string) error
	RetryAll(...func(Task) bool)
	Cancel(string) error
	CancelAll(...func(Task) bool)
	Remove(string) error
	RemoveAll(...func(Task) bool)
}

func New

func New(ctx context.Context, size int) Runner

type State

type State int32
const (
	STATE_PENDING State = iota
	STATE_RUNNING
	STATE_SUCCEEDED
	STATE_CANCELING
	STATE_CANCELED
	STATE_FAILED
)

type Task

type Task interface {
	Id() string
	Name() string
	Err() error
	Log() string
	State() State
	Progress() float64
	ProgressState() string
	Children() []Task
	StartTime() time.Time
	EndTime() time.Time
	DryRun() bool

	Done() <-chan struct{}
	Reset(context.Context)
	Running() bool
	Context() context.Context
	Logger() Logger
	Run()
	Cancel()
	SetName(string)
	SetState(State)
	SetProgress(float64)
	SetProgressState(string)
}

func NewTask

func NewTask(ctx context.Context, name string, fn func(Task) error, taskOpts ...taskOption) Task

type TaskFilterFunc

type TaskFilterFunc func(Task) bool

Jump to

Keyboard shortcuts

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