task

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DispatchTask

type DispatchTask struct {
	TaskID      string // task record ID
	WorkerID    string
	SessionKey  string // original message session_key
	Instruction string
	ReplyTo     platform.InboundMessage // platform info for result delivery
	TaskType    string                  // "immediate"|"countdown"|"scheduled"
	MessageID   string                  // originating platform_messages.id (for session lookup)
}

DispatchTask is the unit of work sent to the TaskDispatcher by the TaskScheduler.

type ExecutionManager

type ExecutionManager interface {
	ExecuteWorker(ctx context.Context, req worker.ExecuteRequest) (model.WorkerExecution, error)
	CancelExecution(ctx context.Context, executionID string) error
}

ExecutionManager manages worker executions.

type ExecutionQuerier

type ExecutionQuerier interface {
	GetByID(id string) (model.WorkerExecution, error)
}

ExecutionQuerier retrieves execution state by ID.

type FailureNotifier

type FailureNotifier interface {
	NotifyTaskFailure(ctx context.Context, messageID string, info model.FailureInfo) error
	NotifyTaskCancelled(ctx context.Context, messageID string, workerName string) error
}

FailureNotifier sends failure and cancellation notifications to users.

type Option

type Option func(*TaskDispatcher)

Option configures a TaskDispatcher.

func WithFailureNotifier

func WithFailureNotifier(fn FailureNotifier) Option

WithFailureNotifier sets the notifier used to inform users about task failures.

func WithWorkerLookup added in v0.0.21

func WithWorkerLookup(lookup WorkerLookup) Option

WithWorkerLookup sets the lookup used to fetch worker metadata for persona injection.

type PlatformFailureNotifier

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

PlatformFailureNotifier implements FailureNotifier by looking up the originating message and sending a failure notification via the appropriate platform sender.

func NewPlatformFailureNotifier

func NewPlatformFailureNotifier(msgStore *store.MessageStore, senders map[string]platform.PlatformSenderAdapter) *PlatformFailureNotifier

NewPlatformFailureNotifier creates a PlatformFailureNotifier.

func (*PlatformFailureNotifier) NotifyTaskCancelled added in v0.0.32

func (n *PlatformFailureNotifier) NotifyTaskCancelled(ctx context.Context, messageID string, workerName string) error

func (*PlatformFailureNotifier) NotifyTaskFailure

func (n *PlatformFailureNotifier) NotifyTaskFailure(ctx context.Context, messageID string, info model.FailureInfo) error

type Reconciler added in v0.0.39

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

Reconciler periodically repairs tasks whose status drifted out of sync with their underlying execution row (engine adapter bugs, OS-killed workers, etc.) so /status reflects the actual state without waiting for a server restart.

func NewReconciler added in v0.0.39

func NewReconciler(taskStore reconcilerTaskStore, execStore reconcilerExecStore, interval time.Duration) *Reconciler

NewReconciler constructs a Reconciler. interval <= 0 falls back to 60s.

func (*Reconciler) Run added in v0.0.39

func (r *Reconciler) Run(ctx context.Context)

Run reconciles on each tick until ctx is cancelled. Call in a goroutine.

type Scheduler

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

Scheduler polls for due tasks and sends them to the TaskDispatcher.

func NewScheduler

func NewScheduler(taskStore schedulerStore, dispatchCh chan<- DispatchTask, pollInterval time.Duration) *Scheduler

NewScheduler creates a Scheduler.

func (*Scheduler) RecoverRunning

func (s *Scheduler) RecoverRunning(ctx context.Context)

RecoverRunning resets all 'running' tasks to 'pending'. Must be called synchronously at startup AFTER the Feeder's RecoverFeeding.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

Run polls for due tasks on each tick until ctx is cancelled.

type SessionStore

type SessionStore interface {
	GetSessionContextForEngine(ctx context.Context, sessionKey, agentID, engine string) (sessionID string, err error)
	UpsertSessionContext(ctx context.Context, sessionKey, agentID, sessionID, engine string) error
	DeleteSessionContextForEngine(ctx context.Context, sessionKey, agentID, engine string) (bool, error)
	ClearSessionContexts(ctx context.Context, sessionKey, beeEngine string) error
}

SessionStore is the subset of store.SessionStore used by the TaskDispatcher.

type TaskDispatcher

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

TaskDispatcher serializes worker executions per WorkerID.

func New

func New(manager ExecutionManager, taskStore TaskStore, sessionStore SessionStore, execStore ExecutionQuerier, in <-chan DispatchTask, engineCfg *enginecfg.Store, opts ...Option) *TaskDispatcher

New constructs a TaskDispatcher.

func (*TaskDispatcher) CancelTask

func (d *TaskDispatcher) CancelTask(ctx context.Context, taskID string) error

CancelTask marks the task cancelled in DB and signals the Run loop to remove it from the in-memory queue or interrupt its executing goroutine. Best-effort: returns once DB is updated; goroutine interruption is async.

func (*TaskDispatcher) ClearSession

func (d *TaskDispatcher) ClearSession(sessionKey string)

ClearSession removes all queued tasks for the given session and clears session contexts. Safe to call from any goroutine — uses a buffered channel to signal the Run loop.

func (*TaskDispatcher) ClearWorker added in v0.0.39

func (d *TaskDispatcher) ClearWorker(sessionKey, workerID string)

ClearWorker removes queued tasks for the given (sessionKey, workerID) pair from the dispatcher's in-memory queues. Safe to call from any goroutine.

The caller is responsible for stopping any currently executing worker via StopExecution and marking tasks cancelled in the database; this method only drains the pending tail of the queue so no future tasks fire for that pair.

func (*TaskDispatcher) Run

func (d *TaskDispatcher) Run(ctx context.Context)

Run processes tasks until ctx is cancelled. Call in a goroutine.

type TaskStore

type TaskStore interface {
	UpdateStatus(ctx context.Context, taskID, status string) error
	CompleteTask(ctx context.Context, taskID string) error
	FailTask(ctx context.Context, taskID string) error
	CancelTask(ctx context.Context, taskID string) error
}

TaskStore is the subset of store.TaskStore used by the TaskDispatcher.

type WorkerLookup added in v0.0.21

type WorkerLookup interface {
	GetByID(id string) (model.Worker, error)
}

WorkerLookup fetches worker metadata for persona injection on new sessions.

Jump to

Keyboard shortcuts

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