Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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, resume bool) (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 WithEngine ¶ added in v0.0.21
WithEngine sets the active engine name so the dispatcher can detect engine switches and discard stale session contexts from a different engine.
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) 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 ¶
RecoverRunning resets all 'running' tasks to 'pending'. Must be called synchronously at startup AFTER the Feeder's RecoverFeeding.
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) 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.