engine

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCron

func ValidateCron(expr string) error

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. Every submitted task runs in its own goroutine. Scheduled tasks are re-fired by EvalSchedules on their cron.

func NewEngine

func NewEngine(ctx context.Context, handlers map[TaskType]TaskHandler) *Engine

NewEngine creates a new Engine. 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.

func (*Engine) GetResult

func (e *Engine) GetResult(id string) *TaskResult

GetResult returns a task by ID (active, completed, or scheduled), or nil.

func (*Engine) Healthz

func (e *Engine) Healthz() bool

Healthz returns true after the engine has been marked ready.

func (*Engine) RecentResults

func (e *Engine) RecentResults() []TaskResult

RecentResults returns the most recent task results, combining active tasks, completed results, and scheduled tasks.

func (*Engine) RemoveResult

func (e *Engine) RemoveResult(id string) bool

RemoveResult removes a task by ID. For active tasks this cancels the goroutine's context. 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) Submit

func (e *Engine) Submit(task Task) (string, error)

Submit starts a task in its own goroutine and returns the assigned UUID.

func (*Engine) SubmitScheduled

func (e *Engine) SubmitScheduled(task Task, sched ScheduleConfig) (string, error)

SubmitScheduled creates a scheduled task. The schedule is evaluated by EvalSchedules. Only cron schedules are supported today.

type ScheduleConfig added in v0.0.17

type ScheduleConfig struct {
	Cron        string `json:"cron,omitempty"`
	BlockHeight *int64 `json:"blockHeight,omitempty"`
}

ScheduleConfig triggers a task on a recurring basis. 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 Task

type Task struct {
	Type   TaskType       `json:"type"`
	Params map[string]any `json:"params,omitempty"`
}

Task is a unit of work submitted by the controller.

type TaskHandler

type TaskHandler func(ctx context.Context, params map[string]any) error

TaskHandler executes a specific task type.

type TaskResult

type TaskResult struct {
	ID          string          `json:"id"`
	Type        string          `json:"type"`
	Status      TaskStatus      `json:"status"`
	Params      map[string]any  `json:"params,omitempty"`
	Schedule    *ScheduleConfig `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. All tasks share this model. When Schedule is non-nil the engine re-executes the task on its cron.

type TaskStatus added in v0.0.15

type TaskStatus string

TaskStatus represents the lifecycle state of a task.

const (
	TaskStatusRunning   TaskStatus = "running"
	TaskStatusCompleted TaskStatus = "completed"
	TaskStatusFailed    TaskStatus = "failed"
)

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"
	TaskConfigApply        TaskType = "config-apply"
	TaskConfigValidate     TaskType = "config-validate"
	TaskConfigReload       TaskType = "config-reload"
	TaskMarkReady          TaskType = "mark-ready"
	TaskConfigureGenesis   TaskType = "configure-genesis"
	TaskConfigureStateSync TaskType = "configure-state-sync"
	TaskSnapshotUpload     TaskType = "snapshot-upload"
	TaskResultExport       TaskType = "result-export"
)

Jump to

Keyboard shortcuts

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