Documentation
¶
Overview ¶
Package queue provides a simple job queue for processing media jobs.
Index ¶
- Variables
- type JobHandler
- type Queue
- func (q *Queue) Cancel(id string) bool
- func (q *Queue) Delete(id string)
- func (q *Queue) Done() <-chan struct{}
- func (q *Queue) GetAllJobs() []*clip.Job
- func (q *Queue) GetJob(id string) *clip.Job
- func (q *Queue) IfLive(id string, fn func())
- func (q *Queue) Reinstate(job *clip.Job)
- func (q *Queue) Requeue(job *clip.Job) error
- func (q *Queue) Restore(job *clip.Job)
- func (q *Queue) SetProgress(id string, percent int) *clip.Job
- func (q *Queue) SetStatusFunc(fn StatusFunc)
- func (q *Queue) Start(ctx context.Context)
- func (q *Queue) Stop()
- func (q *Queue) Submit(job *clip.Job) error
- type StatusFunc
Constants ¶
This section is empty.
Variables ¶
var ErrJobActive = errors.New("a job with this id is already active")
ErrJobActive is returned when a job is submitted while one with the same id is already queued or running.
var ErrJobPanicked = errors.New("job handler panicked")
ErrJobPanicked is recorded against a job whose handler panicked.
var ErrQueueStopped = errors.New("queue is stopped")
ErrQueueStopped is returned when a job is submitted to a stopped queue.
Functions ¶
This section is empty.
Types ¶
type JobHandler ¶
JobHandler is a function that handles jobs.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a job queue.
func NewQueue ¶
func NewQueue(workers int, handler JobHandler) *Queue
NewQueue creates a new job queue.
Parameters:
- workers: How many jobs may run at once.
- handler: Invoked for each job.
Returns:
- queue: A queue ready to Start.
func (*Queue) Cancel ¶
Cancel stops a pending or processing job.
Parameters:
- id: The clip to cancel.
Returns:
- canceled: True when a pending or processing job was canceled.
func (*Queue) Delete ¶
Delete removes a job from the in-memory map.
Parameters:
- id: The clip to remove.
func (*Queue) Done ¶
func (q *Queue) Done() <-chan struct{}
Done returns a channel that is closed when the queue is stopped.
Returns:
- done: Closed on teardown.
func (*Queue) GetAllJobs ¶
GetAllJobs returns every job, newest first.
Returns:
- jobs: Copies of every registered job.
func (*Queue) GetJob ¶
GetJob gets a job by ID, as a copy.
Parameters:
- id: The clip to read.
Returns:
- job: A copy of the job, nil when the queue does not have it.
func (*Queue) IfLive ¶
IfLive runs fn only while the queue still owns the job, holding the read lock for its duration.
Parameters:
- id: The clip the caller is about to write.
- fn: The write.
func (*Queue) Reinstate ¶
Reinstate puts a job back after a delete that could not be completed.
Parameters:
- job: The job Delete took.
func (*Queue) Requeue ¶
Requeue puts an idle job back on the queue for another attempt.
Parameters:
- job: The clip to run again.
Returns:
- err: ErrJobActive when a worker holds the job or the channel already has it.
func (*Queue) Restore ¶
Restore registers a job without enqueueing it.
Parameters:
- job: The clip to track without running.
func (*Queue) SetProgress ¶
SetProgress records how far a render has got.
Parameters:
- id: The clip being rendered.
- percent: Progress so far.
Returns:
- job: The updated job, nil when the queue no longer has it.
func (*Queue) SetStatusFunc ¶
func (q *Queue) SetStatusFunc(fn StatusFunc)
SetStatusFunc registers a callback invoked on job status changes.
Parameters:
- fn: The callback, or nil to stop reporting.
type StatusFunc ¶
StatusFunc is called whenever a job status changes.