Documentation
¶
Overview ¶
Package workqueue is the host's side of the media worker (media/worker): the River schema it drains in the host database, insert-only enqueueing and cancelling of its jobs, and processing progress for the read API. It needs neither ffmpeg nor libvips, so hosts that only presign, commit and read link it instead of the worker.
Index ¶
- Constants
- Variables
- func AudioInsertOpts() *river.InsertOpts
- func ClearProgress(ctx context.Context, pool *pgxpool.Pool, schema string, id int64) error
- func Migrate(ctx context.Context, pool *pgxpool.Pool, schema string) error
- func NewProgressSource(pool *pgxpool.Pool, schema string) (media.ProgressSource, error)
- func RefMatch(ref contentref.ContentRef) ([]byte, *string, error)
- func SetProgress(ctx context.Context, pool *pgxpool.Pool, schema string, id int64, ...) error
- func ValidSchema(schema string) error
- func VideoInsertOpts() *river.InsertOpts
- type AudioArgs
- type ImageArgs
- type Queue
- type VideoArgs
Constants ¶
const ( ImageQueue = "media_image" // image variants, slots, inline images; placement of staged images VideoQueue = "media_video" // video encodes and subtitle sidecars; placement of staged videos AudioQueue = "media_audio" // audio file encodes (minutes, never behind hours of video); placement of staged audio MaxAttempts = 5 )
The worker's jobs live in their own River schema in the host database, so the heavy worker never joins (or wins leadership of) the host's River client. Each host names its schema (e.g. "doujins_media_worker"): hosts sharing a database must not share one, or one host's worker takes the other's jobs. Queue names are fixed within a schema.
Variables ¶
var EncodeKinds = []string{VideoArgs{}.Kind(), AudioArgs{}.Kind()}
EncodeKinds are the job kinds that report encode progress.
Functions ¶
func AudioInsertOpts ¶ added in v0.56.0
func AudioInsertOpts() *river.InsertOpts
AudioInsertOpts are an audio job's insert options.
func ClearProgress ¶
ClearProgress drops a finished job's progress.
func Migrate ¶
Migrate creates schema and applies River's migrations. Hosts run it in their migrate step; the worker also runs it at start.
func NewProgressSource ¶
NewProgressSource reads encode progress from the video and audio jobs in the host's worker schema, for media.ReaderOptions.Progress. One indexed query per read of an item with a pending video or audio file.
func RefMatch ¶
func RefMatch(ref contentref.ContentRef) ([]byte, *string, error)
RefMatch is the jsonb containment and version a job query matches ref's jobs by.
func SetProgress ¶
func SetProgress(ctx context.Context, pool *pgxpool.Pool, schema string, id int64, files map[string]media.EncodeProgress) error
SetProgress records a running job's per-file progress (the worker's reports).
func ValidSchema ¶ added in v0.54.0
ValidSchema requires a lowercase Postgres identifier for the worker's schema.
func VideoInsertOpts ¶
func VideoInsertOpts() *river.InsertOpts
VideoInsertOpts are a video job's insert options.
Types ¶
type AudioArgs ¶ added in v0.56.0
type AudioArgs struct {
Ref contentref.ContentRef `json:"ref"`
}
AudioArgs encodes a manifest's audio files (media.Audio kinds).
type ImageArgs ¶
type ImageArgs struct {
Ref contentref.ContentRef `json:"ref"`
Slot string `json:"slot,omitempty"`
After int64 `json:"after,omitempty"` // the running job this one follows
}
ImageArgs derives a ref's image variants, zip, slots and inline images, or one slot or inline image when Slot is set.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the host's insert-only client for the worker's jobs; it is the uploads' media.ProcessQueue.
func (*Queue) Cancel ¶
func (q *Queue) Cancel(ctx context.Context, ref contentref.ContentRef) (int, error)
Cancel cancels ref's queued and running image and video jobs, every stage: a running job's context is cancelled, so an encode is killed and publishes nothing further. It returns how many jobs it cancelled.
func (*Queue) Enqueue ¶
Enqueue asks the worker to process job: an image job for kinds with image variants, slots or inline images (one pending job per ref and slot, with a follow-up behind a running one), and a video job for a video or audio kind's manifest.
type VideoArgs ¶
type VideoArgs struct {
Ref contentref.ContentRef `json:"ref"`
}
VideoArgs encodes a manifest's video files.