task

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending   = "pending"
	StatusRunning   = "running"
	StatusSucceeded = "succeeded"
	StatusFailed    = "failed"
)

Variables

View Source
var (
	ErrNotFound  = errors.New("not found")
	ErrCanceled  = errors.New("canceled")
	ErrQueueFull = errors.New("queue full")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Message  *string
	Progress *float32
}

func NewEvent

func NewEvent(funcs ...EventFunc) Event

type EventFunc

type EventFunc func(p *Event)

func WithMessage

func WithMessage(message string) EventFunc

func WithProgress

func WithProgress(progress float32) EventFunc

type Factory

type Factory func(id ID, payload []byte) (Task, error)

Factory rebuilds a concrete task from its persisted data.

type Handler

type Handler interface {
	Handle(ctx context.Context, task Task, events chan Event) error
}

type HandlerFunc

type HandlerFunc func(ctx context.Context, task Task, events chan Event) error

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, task Task, events chan Event) error

type ID

type ID string

func NewID

func NewID() ID

type PersistentRunner

type PersistentRunner interface {
	RegisterFactory(taskType Type, factory Factory)
}

PersistentRunner is an extension of Runner that supports registering deserialization factories for persistence.

type Runner

type Runner interface {
	ScheduleTask(ctx context.Context, task Task) error
	GetTaskState(ctx context.Context, id ID) (*State, error)
	GetTask(ctx context.Context, id ID) (Task, error)
	ListTasks(ctx context.Context) ([]StateHeader, error)
	RegisterTask(taskType Type, handler Handler)
	// CancelTask cancels a scheduled or running task
	// A canceled task should return the error ErrCanceled
	CancelTask(ctx context.Context, id ID) error
	Run(ctx context.Context) error
}

type State

type State struct {
	StateHeader
	FinishedAt time.Time
	Progress   float32
	Error      error
	Message    string
}

type StateHeader

type StateHeader struct {
	ID          ID
	Type        Type
	ScheduledAt time.Time
	Status      Status
}

type Status

type Status string

type Task

type Task interface {
	json.Marshaler
	json.Unmarshaler

	ID() ID
	Type() Type
}

type Type

type Type string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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