Documentation
¶
Index ¶
- Variables
- func ValidateCron(expr string) error
- type Engine
- func (e *Engine) EvalSchedules()
- func (e *Engine) GetResult(id string) *TaskResult
- func (e *Engine) Healthz() bool
- func (e *Engine) RecentResults() []TaskResult
- func (e *Engine) RemoveResult(id string) bool
- func (e *Engine) Status() StatusResponse
- func (e *Engine) Submit(task Task) (string, error)
- func (e *Engine) SubmitScheduled(task Task, sched Schedule) (string, error)
- type Schedule
- type StatusResponse
- type Task
- type TaskHandler
- type TaskResult
- type TaskType
Constants ¶
This section is empty.
Variables ¶
var ErrBusy = errors.New("a task is already running")
ErrBusy is returned by Submit when a task is already running.
Functions ¶
func ValidateCron ¶
ValidateCron checks whether a cron expression is syntactically valid.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the task executor. One-shot tasks are serialized through a channel with a TryLock gate. Scheduled tasks run in their own goroutines when their cron fires. Both share the unified TaskResult model.
func NewEngine ¶
func NewEngine(ctx context.Context, handlers map[TaskType]TaskHandler) *Engine
NewEngine creates a new Engine and starts its worker loop. The engine runs until ctx is cancelled.
func (*Engine) EvalSchedules ¶
func (e *Engine) EvalSchedules()
EvalSchedules checks all scheduled tasks and fires any that are due. Scheduled tasks run in their own goroutines, bypassing the one-shot lock.
func (*Engine) GetResult ¶
func (e *Engine) GetResult(id string) *TaskResult
GetResult returns a task by ID (one-shot result or scheduled), or nil.
func (*Engine) RecentResults ¶
func (e *Engine) RecentResults() []TaskResult
RecentResults returns the most recent task results (newest first), combining completed one-shot results and active scheduled tasks.
func (*Engine) RemoveResult ¶
RemoveResult removes a task by ID. For scheduled tasks this stops the schedule. Returns true if found.
func (*Engine) Status ¶
func (e *Engine) Status() StatusResponse
Status returns the engine's current state.
func (*Engine) SubmitScheduled ¶
SubmitScheduled creates a scheduled task. Returns the task ID. Currently only cron schedules are supported; block-height scheduling is reserved for future use. The schedule is evaluated by EvalSchedules.
type Schedule ¶
type Schedule struct {
Cron string `json:"cron,omitempty"`
BlockHeight *int64 `json:"blockHeight,omitempty"`
}
Schedule defines when a task should recur. Exactly one field should be set. Cron is supported today; BlockHeight is reserved for future use.
type StatusResponse ¶
type StatusResponse struct {
Status string `json:"status"`
}
StatusResponse is the shape returned by the status endpoint.
type TaskHandler ¶
TaskHandler executes a specific task type.
type TaskResult ¶
type TaskResult struct {
ID string `json:"id"`
Type string `json:"type"`
Params map[string]any `json:"params,omitempty"`
Schedule *Schedule `json:"schedule,omitempty"`
Error string `json:"error,omitempty"`
SubmittedAt time.Time `json:"submittedAt"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
NextRunAt *time.Time `json:"nextRunAt,omitempty"`
}
TaskResult records a task and its outcome. Both one-shot and scheduled tasks share this model. Scheduled tasks persist until deleted; one-shot results are kept in a bounded history.
type TaskType ¶
type TaskType string
TaskType identifies the kind of task to execute.
const ( TaskSnapshotRestore TaskType = "snapshot-restore" TaskDiscoverPeers TaskType = "discover-peers" TaskConfigPatch TaskType = "config-patch" TaskMarkReady TaskType = "mark-ready" TaskUpdatePeers TaskType = "update-peers" TaskConfigureGenesis TaskType = "configure-genesis" TaskConfigureStateSync TaskType = "configure-state-sync" TaskSnapshotUpload TaskType = "snapshot-upload" )