job

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StateCreated = State("created")

	StateRunning   = State("running")
	StateCanceling = State("canceling")

	StateSucceeded = State("succeeded")
	StateFailed    = State("failed")
	StateCanceled  = State("canceled")
)

Functions

func IsDone

func IsDone(state State) bool

func IsPending

func IsPending(state State) bool

Types

type Context

type Context interface {
	ID() string
	Context() context.Context
	Logger() log.Logger
	Labels() labels.Set
	SetProgress(progress float64)
	SetResult(result any)
	GetParams() any
}

type Func

type Func func(ctx Context) error

func Wrap

func Wrap(fn func(context.Context) error) Func

type Job

type Job interface {
	ID() string
	Labels() labels.Set
	CreatedAt() time.Time
	StartedAt() time.Time
	EndedAt() time.Time
	Run(ctx context.Context, params any) bool
	Wait()
	Cancel() bool
	Result() any
	Err() error
	State() State
	Context() context.Context
	Progress() float64
	ExecutionTime() time.Duration
	IsExecuting() bool
	IsDone() bool
	IsState(state State) bool
	Stats() *Stats
}

func New

func New(id string, fn Func, opts ...Option) Job

type Option

type Option func(*job)

func WithLabel

func WithLabel(key, val string) Option

func WithLabels

func WithLabels(labels map[string]string) Option

func WithLogger

func WithLogger(logger log.Logger) Option

type State

type State string

type Stats

type Stats struct {
	ID            string        `json:"id"`
	State         string        `json:"state"`
	Progress      float64       `json:"progress"`
	StartedAt     time.Time     `json:"started_at"`
	ExecutionTime time.Duration `json:"execution_time"`
	Labels        labels.Set    `json:"labels"`
	Error         string        `json:"error"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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