Help us shape the future of Go! Take the 2026 Go Developer Survey

queue

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package queue provides a simple job queue for processing media jobs.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrJobPanicked = errors.New("job handler panicked")

ErrJobPanicked is recorded against a job whose handler panicked.

View Source
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

type JobHandler func(ctx context.Context, job *clip.Job) error

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

func (q *Queue) Cancel(id string) bool

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

func (q *Queue) Delete(id string)

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

func (q *Queue) GetAllJobs() []*clip.Job

GetAllJobs returns every job, newest first.

Returns:

  • jobs: Copies of every registered job.

func (*Queue) GetJob

func (q *Queue) GetJob(id string) *clip.Job

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

func (q *Queue) IfLive(id string, fn func())

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

func (q *Queue) Reinstate(job *clip.Job)

Reinstate puts a job back after a delete that could not be completed.

Parameters:

  • job: The job Delete took.

func (*Queue) Requeue

func (q *Queue) Requeue(job *clip.Job) error

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

func (q *Queue) Restore(job *clip.Job)

Restore registers a job without enqueueing it.

Parameters:

  • job: The clip to track without running.

func (*Queue) SetProgress

func (q *Queue) SetProgress(id string, percent int) *clip.Job

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.

func (*Queue) Start

func (q *Queue) Start(ctx context.Context)

Start starts the job queue workers.

Parameters:

  • ctx: Lifetime for the queue and for every job.

func (*Queue) Stop

func (q *Queue) Stop()

Stop stops the job queue and waits for its workers.

func (*Queue) Submit

func (q *Queue) Submit(job *clip.Job) error

Submit submits a job to the queue.

Parameters:

  • job: The clip to queue.

Returns:

  • err: ErrJobActive when the id is already queued or running.

type StatusFunc

type StatusFunc func(job *clip.Job)

StatusFunc is called whenever a job status changes.

Jump to

Keyboard shortcuts

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