jobs

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartPaused

func StartPaused() func(disp *Dispatcher)

Types

type Dispatcher

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

func New

func New(options ...Option) *Dispatcher

func (*Dispatcher) ClearDone

func (d *Dispatcher) ClearDone() []*Job

ClearDone removes all the jobs that are not running. The jobs that were cleaned up will be returned.

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close cancels the running tasks and waits for the dispatcher to stop

func (*Dispatcher) Enqueue

func (d *Dispatcher) Enqueue(task Task) *Job

Enqueue adds a new job to the wait queue. If there is something that can execute the job immediately, it will be started.

func (*Dispatcher) Job

func (d *Dispatcher) Job(id uuid.UUID) *Job

Job returns the job with the given ID.

func (*Dispatcher) List

func (d *Dispatcher) List() []*Job

List returns the list of active jobs

func (*Dispatcher) Subscribe

func (d *Dispatcher) Subscribe() *Subscription

Subscribe starts a new subscription for job updates.

type DisplayableTask

type DisplayableTask interface {
	PreferredTemplate() string
}

type Job

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

Job is a handle to a running job

func (*Job) Cancel

func (j *Job) Cancel()

Cancel cancels a running job

func (*Job) Cleanup

func (j *Job) Cleanup()

func (*Job) CreatedAt

func (j *Job) CreatedAt() time.Time

func (*Job) Data

func (j *Job) Data() map[string]interface{}

func (*Job) Err

func (j *Job) Err() error

Err returns the error from running the job

func (*Job) GetData

func (j *Job) GetData(key string) interface{}

func (*Job) ID

func (j *Job) ID() uuid.UUID

func (*Job) LastMessage added in v0.0.7

func (j *Job) LastMessage() string

func (*Job) LastUpdate

func (j *Job) LastUpdate() Update

func (*Job) MessageHistory added in v0.0.7

func (j *Job) MessageHistory() []string

func (*Job) SetData

func (j *Job) SetData(key string, value interface{})

func (*Job) State

func (j *Job) State() JobState

func (*Job) Task

func (j *Job) Task() Task

Task returns the original task of the job

type JobState

type JobState int
const (
	StateQueued JobState = iota + 1
	StateRunning
	StateCancelling
	StateCompleted
	StateError
	StateCancelled
)

func (JobState) String

func (js JobState) String() string

func (JobState) Terminal

func (js JobState) Terminal() bool

type Option

type Option func(disp *Dispatcher)

type RunContext

type RunContext interface {
	PostUpdate(update Update)
	PostMessage(msg string)
	TempFile(pattern string) (*os.File, error)
	Set(key string, value interface{})
	// contains filtered or unexported methods
}

type SliceJobStore

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

func NewSliceJobStore

func NewSliceJobStore() *SliceJobStore

func (*SliceJobStore) Add

func (js *SliceJobStore) Add(job *Job)

func (*SliceJobStore) ClearDone

func (js *SliceJobStore) ClearDone() []*Job

func (*SliceJobStore) Find

func (js *SliceJobStore) Find(id uuid.UUID) *Job

func (*SliceJobStore) List

func (js *SliceJobStore) List() []*Job

type StateTransitionSubscriptionEvent

type StateTransitionSubscriptionEvent struct {
	Job       *Job
	FromState JobState
	ToState   JobState
}

type Subscription

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

func (*Subscription) Chan

func (s *Subscription) Chan() chan SubscriptionEvent

func (*Subscription) Close

func (s *Subscription) Close()

type SubscriptionEvent

type SubscriptionEvent interface{}

type Task

type Task interface {
	String() string

	// Execute executes the task with the given context.
	Execute(ctx context.Context, runContext RunContext) error
}

Task is something that a job is to perform

type Update

type Update struct {
	Summary string
	Percent float64
}

type UpdateSubscriptionEvent

type UpdateSubscriptionEvent struct {
	Job    *Job
	Update Update
}

Jump to

Keyboard shortcuts

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