task

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 10 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

View Source
var ExportedQueueKey = queueKey

ExportedQueueKey is exported for testing only.

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, workerID, input, sessionID string) (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
}

FailureNotifier sends failure notifications to users when a worker execution fails at the system level (e.g. API error, content filtering) and the worker itself had no chance to call send_message.

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.

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) NotifyTaskFailure

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

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 {
	GetSessionContext(ctx context.Context, sessionKey, agentID string) (string, error)
	UpsertSessionContext(ctx context.Context, sessionKey, agentID, sessionID string) error
	ClearSessionContexts(ctx context.Context, sessionKey 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, 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) Run

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

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

type TaskStore

type TaskStore interface {
	SetExecution(ctx context.Context, taskID, executionID, 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.

Jump to

Keyboard shortcuts

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