schema

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context

	// 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 uint64)

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

	// Return the metadata options, used by the metadata task
	MetaOpts func() []metadata.Option
}

Task Context composes an underlying context.Context

type Event

type Event struct {
	Name   EventName `` /* 129-byte string literal not displayed */
	Status Status    `json:"status" help:"Snapshot of the task at the time of the event."`
}

Event reports a change to a task tracked by a Manager - see Manager.Subscribe.

func (Event) String

func (e Event) String() string

type EventName

type EventName string

EventName identifies what changed about a task when an Event is emitted.

const (
	EventAdded     EventName = "added"     // a task was registered with Manager.Add
	EventStarted   EventName = "started"   // a task's Run goroutine was launched
	EventProgress  EventName = "progress"  // a task reported progress
	EventResult    EventName = "result"    // a task set its result
	EventCancelled EventName = "cancelled" // a task's cancellation was requested
	EventFinished  EventName = "finished"  // a task's Run goroutine returned
	EventRemoved   EventName = "removed"   // a task was unregistered with Manager.Remove
)

type Progress

type Progress struct {
	Current uint64 `json:"current,omitempty" help:"How far the task has got, in task-defined units (e.g. bytes, frames, streams)." example:"512"`
	Total   uint64 `` /* 136-byte string literal not displayed */
}

Progress reports how far a running task has got. Total is 0 if not known in advance, in which case a percentage can't be computed.

func (Progress) Percent

func (p Progress) Percent() float64

func (Progress) Valid

func (p Progress) Valid() bool

type ReadSeeker

type ReadSeeker struct {
	io.ReadSeeker
	// contains filtered or unexported fields
}

func NewReadSeeker

func NewReadSeeker(r io.Reader) (*ReadSeeker, error)

Create a new in-memory ReadSeeker from a Reader. If the reader is already a ReadSeeker, it is returned as-is. Otherwise, the reader is read into memory and a new ReadSeeker is created.

func (ReadSeeker) MarshalJSON

func (r ReadSeeker) MarshalJSON() ([]byte, error)

MarshalJSON renders the input's name - the embedded io.ReadSeeker has no exported fields of its own (and couldn't be usefully serialized as a byte stream anyway), so the default encoding would otherwise produce {}.

func (ReadSeeker) Name

func (r ReadSeeker) Name() string

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 `json:"uuid" help:"Unique identifier for the task." example:"123e4567-e89b-12d3-a456-426614174000"`
	Name string    `json:"name" help:"Caller-chosen name for the task" example:"transcode"`
	Task string    `json:"task" help:"The task class." example:"metadata"`
	Progress
	Result    any       `json:"result,omitempty" help:"Task-defined result value, set once the task has finished successfully."`
	Started   time.Time `` /* 126-byte string literal not displayed */
	Finished  time.Time `json:"finished,omitzero" help:"When the task finished; zero until the task has finished." example:"2026-07-27T09:05:00Z"`
	Cancelled bool      `json:"cancelled,omitempty" help:"Whether the task was cancelled, regardless of the error it returned." example:"false"`
	Err       error     `json:"error,omitempty" help:"Error the task returned, if any." example:"decode failed: unexpected EOF"`
}

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)

MarshalJSON renders Err as its message string

func (Status) State

func (s Status) State() State

State reports the task's current lifecycle state.

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON is the inverse of MarshalJSON: it reads Err back as a plain error carrying that message string

type Task

type Task interface {
	// Task returns the task's own kind, e.g. "metadata" - fixed by the
	// implementation, unlike the caller-chosen name passed to Manager.Add.
	Task() string

	// Validate reports whether the task is well-formed and can be run at
	// all (e.g. a non-nil reader). Manager.Add calls this before the task
	// is even registered, so a malformed request is rejected immediately
	// rather than accepted as a task that's already doomed to fail once
	// started.
	Validate() error

	// Run the task
	Run(ctx Context) error
}

Task is the interface that all tasks must implement. A task is a unit of work that can be run asynchronously, and can report progress and results back to the caller.

type TaskEventRequest

type TaskEventRequest struct {
	UUID  *string     `` /* 136-byte string literal not displayed */
	Event []EventName `` /* 189-byte string literal not displayed */
}

TaskEventRequest filters the events streamed by GET /task/event. A nil UUID or empty Event means "don't filter on this".

func (TaskEventRequest) Query

func (r TaskEventRequest) Query() url.Values

type TaskList

type TaskList struct {
	TaskListRequest
	Count uint64   `json:"count" help:"Number of tasks matching the request." example:"1"`
	Body  []Status `json:"body,omitempty" help:"List of tasks."`
}

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

func (TaskList) String

func (t TaskList) String() string

type TaskListRequest

type TaskListRequest struct {
	State *State `json:"state,omitempty" help:"Filter by lifecycle state." enum:"not_started,running,cancelled,error,done" example:"running"`
	pg.OffsetLimit
}

TaskListRequest filters the tasks returned by Manager.ListTasks. A nil State means "don't filter by state".

func (TaskListRequest) Query

func (r TaskListRequest) Query() url.Values

Jump to

Keyboard shortcuts

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