task

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioEncodeMediaRequest

type AudioEncodeMediaRequest struct {
	Reader io.Reader `json:"-"`
	ProbeRequestOpts
	Stream  *uint64              `json:"stream,omitempty" name:"stream" help:"Index of the stream to encode; 0-based." example:"0"`
	Profile profile.AudioProfile `json:"profile,omitempty" name:"profile" help:"Audio encoding profile to use."`
}

func (*AudioEncodeMediaRequest) Run

func (task *AudioEncodeMediaRequest) Run(ctx Context) (err error)

type AudioEncodeMediaResponse

type AudioEncodeMediaResponse struct {
	// Path is the location of the encoded output. For now this is always a
	// temporary file, until a real upload/storage destination exists.
	Path string `json:"path" help:"Path to the encoded output file."`
}

AudioEncodeMediaResponse is the result of a successful AudioEncodeMediaRequest.

type Context

type Context struct {
	context.Context

	// Otel Tracer (can be nil)
	Tracer trace.Tracer

	// Progress reports how far the task has got, in task-defined units (e.g.
	// bytes, frames, streams) - total is 0 if not known in advance.
	Progress func(current, total int64)

	// Result sets the task's output, retrievable afterwards via the
	// Manager's Status.
	Result func(any)
}

Task Context composes an underlying context.Context

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Manager is an in-memory registry of tasks: Add one to get back a UUID, then Run or Cancel it by that UUID.

func NewManager

func NewManager(tracer trace.Tracer) *Manager

NewManager creates a new, empty task manager. tracer can be nil.

func (*Manager) Add

func (m *Manager) Add(ctx context.Context, name string, task Task) (_ uuid.UUID, err error)

Add registers task under name and returns its UUID. The task isn't run until Run is called with that UUID.

func (*Manager) Cancel

func (m *Manager) Cancel(ctx context.Context, id uuid.UUID) (err error)

Cancel stops the running task registered under id. It's a no-op if the task has already finished or was never started.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) (err error)

Close cancels every task that's still running, then waits for each to finish (i.e. for its Run goroutine to return) or for ctx to be done, whichever comes first - so a shutdown sequence can bound how long it waits by passing a context with a deadline. It's safe to call even if some or all tasks have already finished or were never started.

func (*Manager) List

func (m *Manager) List(ctx context.Context, req TaskListRequest) (_ TaskList, err error)

List returns a snapshot of the tasks matching req, in the order they were added.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, id uuid.UUID) (err error)

Run starts the task registered under id in a new goroutine, using ctx as the parent for cancellation and tracing, and returns immediately - use Cancel to stop the task, and Status to poll its progress or result.

func (*Manager) Status

func (m *Manager) Status(id uuid.UUID) (*Status, error)

Status returns a snapshot of the task registered under id.

func (*Manager) Wait

func (m *Manager) Wait(ctx context.Context, id uuid.UUID) (_ *Status, err error)

Wait blocks until the task registered under id finishes, or until ctx is done, whichever comes first, then returns its final status. It returns an error if the task hasn't been started (there's nothing to wait for).

type MetadataRequest

type MetadataRequest struct {
	Reader io.Reader `json:"-"`
}

func (MetadataRequest) Query

func (r MetadataRequest) Query() url.Values

func (*MetadataRequest) Run

func (task *MetadataRequest) Run(ctx Context) (err error)

type MetadataResponse

type MetadataResponse struct {
	Name     string             `json:"name,omitempty" help:"Name of the probed input, if known (e.g. the uploaded filename)." example:"sample.mp3"`
	Type     string             `json:"type,omitempty" help:"Detected content type (MIME type) of the input, e.g. \"video/mp4\"." example:"video/mp4"`
	Metadata []profile.Metadata `json:"metadata,omitempty" help:"Container-level metadata tags, e.g. \"title\", \"artist\"; excludes artwork and chapters."`
	Artwork  []profile.Artwork  `json:"artwork,omitempty" help:"Artwork images embedded in the input, e.g. album cover art."`
}

type ProbeMediaRequest

type ProbeMediaRequest struct {
	Reader io.Reader `json:"-"`
	ProbeRequestOpts
}

type ProbeMediaTask

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

func NewProbeMediaTask

func NewProbeMediaTask(req ProbeMediaRequest) (*ProbeMediaTask, error)

func (*ProbeMediaTask) Run

func (task *ProbeMediaTask) Run(ctx Context) (err error)

type ProbeRequestOpts

type ProbeRequestOpts struct {
	Format string   `json:"format,omitempty" name:"format" help:"Input format name (e.g. mpegts)"`
	Opts   []string `json:"opts,omitempty" name:"opts" help:"Input format options"`
}

func (ProbeRequestOpts) Query

func (r ProbeRequestOpts) Query() url.Values

Query returns the Format/Opts fields as URL query parameters, for a client to attach to the probe request (Reader is carried as the request body, not a query parameter).

type ProbeResponse

type ProbeResponse struct {
	Name     string                   `json:"name,omitempty" help:"Name of the probed input, if known (e.g. the uploaded filename)." example:"sample.mp3"`
	Format   *profile.FormatMeta      `json:"format,omitempty" help:"Detected container format."`
	Duration profile.Duration         `` /* 236-byte string literal not displayed */
	Streams  []*profile.StreamProfile `json:"streams,omitempty" help:"Audio, video, subtitle, data, and attachment streams found in the input."`
	Metadata []profile.Metadata       `json:"metadata,omitempty" help:"Container-level metadata tags, e.g. \"title\", \"artist\"; excludes artwork and chapters."`
	Artwork  []profile.Artwork        `json:"artwork,omitempty" help:"Embedded artwork (cover art, thumbnail, etc.) found in the input; absent if none was found."`
	Chapters []profile.Chapter        `json:"chapters,omitempty" help:"Chapter markers found in the input, if any."`
}

type ProbeSourceRequest

type ProbeSourceRequest struct {
	Url string `` /* 137-byte string literal not displayed */
	ProbeRequestOpts
}

Url is a plain string, not *url.URL - go-server's httprequest.Query has no case for a *url.URL field (only strings, numbers, bools, slices, and time.Time), so a string keeps ProbeSourceRequest decodable as a whole via the generic decoder rather than needing a field-by-field workaround. It's parsed to *url.URL in ProbeSourceTask.Run.

type ProbeSourceTask

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

func NewProbeSourceTask

func NewProbeSourceTask(req ProbeSourceRequest) (*ProbeSourceTask, error)

func (*ProbeSourceTask) Run

func (task *ProbeSourceTask) Run(ctx Context) (err error)

type Progress

type Progress struct {
	Current int64
	Total   int64
}

Progress reports how far a running task has got, in task-defined units (e.g. bytes, frames, streams). Total is 0 if not known in advance, in which case a percentage can't be computed.

type State

type State string

State is the lifecycle state of a task tracked by a Manager.

const (
	StateNotStarted State = "not_started"
	StateRunning    State = "running"
	StateCancelled  State = "cancelled"
	StateError      State = "error"
	StateDone       State = "done"
)

type Status

type Status struct {
	UUID      uuid.UUID
	Name      string
	Progress  Progress
	Result    any
	Started   time.Time // zero until the task has been run
	Finished  time.Time // zero until the task has finished
	Cancelled bool      // set by Cancel, regardless of the error the task returns
	Err       error
}

Status is a snapshot of a task tracked by a Manager.

func (Status) Duration

func (s Status) Duration() time.Duration

Duration is how long the task has been running, or ran for if it has finished. Zero if the task hasn't started yet.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

func (Status) State

func (s Status) State() State

State reports the task's current lifecycle state.

type Task

type Task interface {
	// Run the task
	Run(ctx Context) error
}

type TaskList

type TaskList []Status

TaskList is a snapshot of the tasks tracked by a Manager, in the order they were added.

type TaskListRequest

type TaskListRequest struct {
	Name  *string `json:"name,omitempty"`
	State *State  `json:"state,omitempty"`
}

TaskListRequest filters the tasks returned by Manager.List. A nil field means "don't filter on this".

Jump to

Keyboard shortcuts

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