Documentation ¶
Index ¶
- Constants
- func IsCancelled(ctx context.Context) bool
- type Job
- type JobExec
- type Manager
- func (m *Manager) Add(ctx context.Context, description string, e JobExec) int
- func (m *Manager) CancelAll()
- func (m *Manager) CancelJob(id int)
- func (m *Manager) GetJob(id int) *Job
- func (m *Manager) GetQueue() []Job
- func (m *Manager) Start(ctx context.Context, description string, e JobExec) int
- func (m *Manager) Stop()
- func (m *Manager) Subscribe(ctx context.Context) *ManagerSubscription
- type ManagerSubscription
- type Progress
- func (p *Progress) AddProcessed(v int)
- func (p *Progress) AddTotal(total int)
- func (p *Progress) Definite()
- func (p *Progress) ExecuteTask(description string, fn func())
- func (p *Progress) Increment()
- func (p *Progress) Indefinite()
- func (p *Progress) SetPercent(percent float64)
- func (p *Progress) SetProcessed(processed int)
- func (p *Progress) SetTotal(total int)
- type Status
- type TaskQueue
Constants ¶
const ProgressIndefinite float64 = -1
ProgressIndefinite is the special percent value to indicate that the percent progress is not known.
Variables ¶
This section is empty.
Functions ¶
func IsCancelled ¶
IsCancelled returns true if cancel has been called on the context.
Types ¶
type Job ¶
type Job struct { ID int Status Status // details of the current operations of the job Details []string Description string // Progress in terms of 0 - 1. Progress float64 StartTime *time.Time EndTime *time.Time AddTime time.Time // contains filtered or unexported fields }
Job represents the status of a queued or running job.
func (*Job) TimeElapsed ¶ added in v0.14.0
TimeElapsed returns the total time elapsed for the job. If the EndTime is set, then it uses this to calculate the elapsed time, otherwise it uses time.Now.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager maintains a queue of jobs. Jobs are executed one at a time.
func (*Manager) CancelAll ¶
func (m *Manager) CancelAll()
CancelAll cancels all of the jobs in the queue. This is the same as calling CancelJob on all jobs in the queue.
func (*Manager) CancelJob ¶
CancelJob cancels the job with the provided id. Jobs that have been started are notified that they are stopping. Jobs that have not yet started are removed from the queue. If no job exists with the provided id, then there is no effect. Likewise, if the job is already cancelled, there is no effect.
func (*Manager) GetJob ¶
GetJob returns a copy of the Job for the provided id. Returns nil if the job does not exist.
func (*Manager) Start ¶
Start adds a job and starts it immediately, concurrently with any other jobs.
type ManagerSubscription ¶
type ManagerSubscription struct { // new jobs are sent to this channel NewJob <-chan Job // removed jobs are sent to this channel RemovedJob <-chan Job // updated jobs are sent to this channel UpdatedJob <-chan Job // contains filtered or unexported fields }
ManagerSubscription is a collection of channels that will receive updates from the job manager.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress is used by JobExec to communicate updates to the job's progress to the JobManager.
func (*Progress) AddProcessed ¶ added in v0.11.0
AddProcessed increments the number of processed work units by the provided amount. This is used to calculate the percentage.
func (*Progress) AddTotal ¶ added in v0.17.0
AddTotal adds to the total number of work units. This is used to calculate the progress percentage.
func (*Progress) Definite ¶ added in v0.17.0
func (p *Progress) Definite()
Definite notifies that the total is known.
func (*Progress) ExecuteTask ¶
ExecuteTask executes a task as part of a job. The description is used to populate the Details slice in the parent Job.
func (*Progress) Increment ¶
func (p *Progress) Increment()
Increment increments the number of processed work units. This is used to calculate the percentage. If total is set already, then the number of processed work units will not exceed the total.
func (*Progress) Indefinite ¶
func (p *Progress) Indefinite()
Indefinite sets the progress to an indefinite amount.
func (*Progress) SetPercent ¶
SetPercent sets the progress percent directly. This value will be overwritten if Indefinite, SetTotal, Increment or SetProcessed is called. Constrains the percent value between 0 and 1, inclusive.
func (*Progress) SetProcessed ¶
SetProcessed sets the number of work units completed. This is used to calculate the progress percentage.
type Status ¶
type Status string
Status is the status of a Job
const ( // StatusReady means that the Job is not yet started. StatusReady Status = "READY" // StatusRunning means that the job is currently running. StatusRunning Status = "RUNNING" // StatusStopping means that the job is cancelled but is still running. StatusStopping Status = "STOPPING" // StatusFinished means that the job was completed. StatusFinished Status = "FINISHED" // StatusCancelled means that the job was cancelled and is now stopped. StatusCancelled Status = "CANCELLED" // StatusFailed means that the job failed. StatusFailed Status = "FAILED" )