worker

package
v0.0.0-...-8e6cb86 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPending = errors.New("pending")
View Source
var ErrSemPending = fmt.Errorf("sem is > 0: %w", ErrPending)

Functions

func CollectRootErrors

func CollectRootErrors(err error) error

func CollectUniqueErrors

func CollectUniqueErrors(inErrs []error) []error

func ContextWithPoolJob

func ContextWithPoolJob(ctx context.Context, p *Pool, j *Job) context.Context

func PoolJobFromContext

func PoolJobFromContext(ctx context.Context) (*Pool, *Job, bool)

func Suspend

func Suspend(ctx context.Context, f func())

func SuspendE

func SuspendE(ctx context.Context, f func() error) error

func SuspendWaitGroup

func SuspendWaitGroup(ctx context.Context, wg *WaitGroup) error

Types

type Hook

type Hook interface {
	Run(*Job) context.Context
}

type Job

type Job struct {
	Name  string
	ID    uint64
	Deps  *WaitGroup
	Do    func(w *Worker, ctx context.Context) error
	State JobState
	Hook  Hook

	TimeScheduled time.Time
	TimeQueued    time.Time
	TimeStart     time.Time
	TimeEnd       time.Time
	// contains filtered or unexported fields
}

func (*Job) Ctx

func (j *Job) Ctx() context.Context

func (*Job) Done

func (j *Job) Done()

func (*Job) DoneWithErr

func (j *Job) DoneWithErr(err error, state JobState)

func (*Job) Err

func (j *Job) Err() error

func (*Job) GetStatus

func (j *Job) GetStatus() status.Statuser

func (*Job) Interactive

func (j *Job) Interactive() bool

func (*Job) IsDone

func (j *Job) IsDone() bool

func (*Job) RunHook

func (j *Job) RunHook()

func (*Job) Status

func (j *Job) Status(status status.Statuser)

func (*Job) Wait

func (j *Job) Wait() <-chan struct{}

type JobError

type JobError struct {
	ID    uint64
	Name  string
	State JobState
	Err   error
	// contains filtered or unexported fields
}

func (JobError) Error

func (e JobError) Error() string

func (JobError) Root

func (e JobError) Root() error

func (JobError) Skipped

func (e JobError) Skipped() bool

func (JobError) Unwrap

func (e JobError) Unwrap() error

type JobState

type JobState int8
const (
	StateUnknown JobState = iota
	StateScheduled
	StateQueued
	StateRunning
	StateSuccess
	StateFailed
	StateSkipped
	StateSuspended
)

func (JobState) IsDone

func (s JobState) IsDone() bool

func (JobState) String

func (s JobState) String() string

type Pool

type Pool struct {
	Workers []*Worker
	// contains filtered or unexported fields
}

func NewPool

func NewPool(n int) *Pool

func (*Pool) Done

func (p *Pool) Done() <-chan struct{}

func (*Pool) Err

func (p *Pool) Err() error

func (*Pool) IsDone

func (p *Pool) IsDone() bool

func (*Pool) Jobs

func (p *Pool) Jobs() []*Job

func (*Pool) Schedule

func (p *Pool) Schedule(ctx context.Context, job *Job) *Job

func (*Pool) Stop

func (p *Pool) Stop(err error)

type StageHook

type StageHook struct {
	OnScheduled func(*Job) context.Context
	OnQueued    func(*Job) context.Context
	OnStart     func(*Job) context.Context
	OnEnd       func(*Job) context.Context
}

func (StageHook) Run

func (h StageHook) Run(j *Job) context.Context

type WaitGroup

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

func WaitGroupChan

func WaitGroupChan[T any](ch <-chan T) *WaitGroup

func WaitGroupJob

func WaitGroupJob(j *Job) *WaitGroup

func WaitGroupOr

func WaitGroupOr(wgs ...*WaitGroup) *WaitGroup

func (*WaitGroup) Add

func (wg *WaitGroup) Add(job *Job)

func (*WaitGroup) AddChild

func (wg *WaitGroup) AddChild(child *WaitGroup)

func (*WaitGroup) AddSem

func (wg *WaitGroup) AddSem()

func (*WaitGroup) Done

func (wg *WaitGroup) Done() <-chan struct{}

func (*WaitGroup) DoneSem

func (wg *WaitGroup) DoneSem()

func (*WaitGroup) Err

func (wg *WaitGroup) Err() error

func (*WaitGroup) IsDone

func (wg *WaitGroup) IsDone() bool

func (*WaitGroup) Jobs

func (wg *WaitGroup) Jobs() []*Job

func (*WaitGroup) Remove

func (wg *WaitGroup) Remove(job *Job)

func (*WaitGroup) RemoveChild

func (wg *WaitGroup) RemoveChild(child *WaitGroup)

func (*WaitGroup) TransitiveCount

func (wg *WaitGroup) TransitiveCount() WaitGroupStats

func (*WaitGroup) TransitiveDo

func (wg *WaitGroup) TransitiveDo(f func(j *Job))

type WaitGroupStats

type WaitGroupStats struct {
	All       uint64
	Done      uint64
	Success   uint64
	Failed    uint64
	Skipped   uint64
	Suspended uint64
}

type Worker

type Worker struct {
	CurrentJob *Job
}

func (*Worker) GetStatus

func (w *Worker) GetStatus() status.Statuser

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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