worker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package worker commits import, chapter, and mail work with application transactions and runs it through the shared PostgreSQL connection pool.

Index

Constants

View Source
const (
	DefaultMailWorkers = 5
)

Variables

This section is empty.

Functions

func FinalAttempt

func FinalAttempt(ctx context.Context) bool

FinalAttempt tells the import use case whether a failure exhausts automatic retries. Direct execution outside the runtime is a single, final attempt.

Types

type Option

type Option func(*settings)

Option extends the runtime with another task on its own queue.

func Chapters

func Chapters(execute func(ctx context.Context, mediaItemID, checksum string) error, concurrency int) Option

Chapters adds the chapter extraction task on the bounded ffprobe queue. concurrency is how many probes may run at once; one is the production default.

func Mail

func Mail(execute func(ctx context.Context, deliveryID string) error, concurrency int) Option

Mail adds the mail delivery task on its own bounded queue so slow SMTP sessions never occupy import or probe workers. Concurrency below one uses the default of five.

type Runtime

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

Runtime shares Bun's pool and never closes it. Stop it before closing Bun.

func New

func New(db *bun.DB, execute func(context.Context, string) error, options ...Option) (*Runtime, error)

New binds the use cases without executing work or starting goroutines.

func (*Runtime) EnqueueChapters

func (r *Runtime) EnqueueChapters(ctx context.Context, tx bun.Tx, mediaItemID, checksum string) error

EnqueueChapters records chapter extraction for one Media Item at one checksum in the caller's transaction. An active task for the same pair is reused, and a task waiting for an automatic retry runs at once instead.

func (*Runtime) EnqueueImport

func (r *Runtime) EnqueueImport(ctx context.Context, tx bun.Tx, albumID string) error

EnqueueImport records work in the caller's transaction. It never executes the import; the caller must commit before workers can see it.

func (*Runtime) EnqueueMail

func (r *Runtime) EnqueueMail(ctx context.Context, tx bun.Tx, deliveryID string) error

EnqueueMail records one delivery attempt in the caller's transaction. Mail jobs are deliberately not unique in River: the delivery record decides whether work remains, and River's required "running" uniqueness would let a job orphaned by a crash block a Curator's deliberate retry until the rescuer runs. A rescued job finds the record already settled and does nothing.

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context) error

Start begins polling. Use the application lifetime, not an HTTP request context.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context) error

Stop drains work, cancelling remaining imports after fifteen seconds. A context error means shutdown is not confirmed; call Stop again before closing Bun.

Jump to

Keyboard shortcuts

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