taskruntime

package
v0.0.0-...-820128f Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package taskruntime provides bounded, durable scheduling for typed background tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admitter

type Admitter interface {
	TryAdmit(context.Context, *database.TaskEntity) (bool, error)
	ReleaseAdmission(string)
}

Admitter reserves execution resources while a task is still queued.

type CancelFunc

type CancelFunc func(context.Context, string, string) (*database.TaskEntity, bool, error)

CancelFunc requests cancellation through a kind's specialized lifecycle service.

type EventSink

type EventSink func(context.Context, string, any) error

EventSink appends a durable task observation.

type Handler

type Handler interface {
	Kind() string
	Run(context.Context, *database.TaskEntity, EventSink) (Outcome, error)
}

Handler reconstructs and executes one durable task kind.

type Manager

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

Manager provides transport-neutral lifecycle inspection while preserving typed cancellation behavior.

func NewManager

func NewManager(tasks *database.TaskRepository) *Manager

NewManager constructs generic lifecycle management over the authoritative tasks table.

func (*Manager) CancelTask

func (manager *Manager) CancelTask(
	ctx context.Context, owner, taskID string,
) (*database.TaskEntity, bool, error)

CancelTask dispatches cancellation to the task kind's specialized service.

func (*Manager) GetTask

func (manager *Manager) GetTask(
	ctx context.Context, owner, taskID string,
) (*database.TaskEntity, bool, error)

GetTask returns an owner-scoped generic lifecycle snapshot.

func (*Manager) ListTasks

func (manager *Manager) ListTasks(
	ctx context.Context, owner string, states []database.TaskState, limit int,
) ([]database.TaskEntity, error)

ListTasks lists every supported durable task kind owned by a session.

func (*Manager) RegisterCancel

func (manager *Manager) RegisterCancel(kind string, cancel CancelFunc) error

RegisterCancel installs the specialized cancellation path for a durable task kind.

type Options

type Options struct {
	Tasks             *database.TaskRepository
	Logger            *slog.Logger
	Workers           int
	PollInterval      time.Duration
	LeaseDuration     time.Duration
	HeartbeatInterval time.Duration
	RecoveryInterval  time.Duration
	DefaultTimeout    time.Duration
	MaxPayloadBytes   int
}

Options configures the generic task-table polling scheduler.

type Outcome

type Outcome struct {
	Value        any    `json:"value,omitempty"`
	Summary      string `json:"summary,omitempty"`
	ErrorCode    string `json:"error_code,omitempty"`
	ErrorMessage string `json:"error_message,omitempty"`
}

Outcome is a handler's canonical structured result and searchable summary.

type Recoverer

type Recoverer interface {
	RecoverExpired(context.Context, time.Time) error
}

Recoverer atomically settles expired owned work for a typed task kind.

type Service

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

Service owns all scheduler and execution goroutines.

func New

func New(options Options, handlers ...Handler) (*Service, error)

New constructs a task runtime with defaults for omitted scheduling options.

func (*Service) CancelActive

func (service *Service) CancelActive(taskID string)

CancelActive interrupts a locally running task after durable cancellation is requested.

func (*Service) Notify

func (service *Service) Notify()

Notify wakes the task-table poller after durable acceptance.

func (*Service) Shutdown

func (service *Service) Shutdown(ctx context.Context) error

Shutdown stops polling and waits for active tasks until the context expires.

func (*Service) Start

func (service *Service) Start(parent context.Context) error

Start begins polling and recovering durable tasks.

type Settler

type Settler interface {
	Settle(context.Context, *database.TaskFinish, Outcome) (bool, error)
}

Settler lets a typed repository commit its canonical outcome in the same transaction as the terminal lifecycle transition.

Jump to

Keyboard shortcuts

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