Documentation
¶
Overview ¶
Package cron provides the cron scheduling subsystem for HotPlex.
Index ¶
- type CronCallback
- type CronJob
- type CronRun
- type CronScheduler
- func (cs *CronScheduler) AddJob(job *CronJob) error
- func (cs *CronScheduler) GetJob(id string) *CronJob
- func (cs *CronScheduler) ListJobs() []*CronJob
- func (cs *CronScheduler) ListRuns(jobID string) []*CronRun
- func (cs *CronScheduler) PauseJob(id string) error
- func (cs *CronScheduler) RemoveJob(id string) error
- func (cs *CronScheduler) ResumeJob(id string) error
- func (cs *CronScheduler) SetRunsStore(rs *RunsStore)
- func (cs *CronScheduler) Start() error
- func (cs *CronScheduler) Stop() context.Context
- type CronStore
- type Event
- type ExecuteRequest
- type ExecuteResult
- type Executor
- type JobType
- type OutputFormat
- type RunsStore
- type WebhookCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CronCallback ¶
CronCallback handles job lifecycle events.
type CronJob ¶
type CronJob struct {
ID string `json:"id"`
CronExpr string `json:"cron_expr"`
Prompt string `json:"prompt"`
SessionKey string `json:"session_key,omitempty"`
WorkDir string `json:"work_dir,omitempty"`
Type JobType `json:"type"`
TimeoutMins int `json:"timeout_mins"`
Retries int `json:"retries"`
RetryDelay time.Duration `json:"retry_delay"`
OutputFormat OutputFormat `json:"output_format"`
OutputSchema string `json:"output_schema,omitempty"`
Enabled bool `json:"enabled"`
Silent bool `json:"silent"`
NotifyOn []Event `json:"notify_on"`
CreatedBy string `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
LastRun time.Time `json:"last_run"`
LastError string `json:"last_error,omitempty"`
NextRun time.Time `json:"next_run"`
RunCount int `json:"run_count"`
OnComplete string `json:"on_complete,omitempty"`
OnFail string `json:"on_fail,omitempty"`
}
CronJob represents a scheduled task.
type CronRun ¶
type CronRun struct {
ID string `json:"id"`
JobID string `json:"job_id"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
Duration time.Duration `json:"duration"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
RetryCount int `json:"retry_count"`
Response string `json:"response,omitempty"`
}
CronRun represents a single execution of a cron job.
type CronScheduler ¶
type CronScheduler struct {
// contains filtered or unexported fields
}
CronScheduler manages scheduled jobs using robfig/cron/v3.
func NewCronScheduler ¶
func NewCronScheduler(store *CronStore, executor *Executor, logger *slog.Logger, maxConcurrent int) *CronScheduler
NewCronScheduler creates a scheduler backed by a store and executor. maxConcurrent limits how many jobs run simultaneously (default 4).
func (*CronScheduler) AddJob ¶
func (cs *CronScheduler) AddJob(job *CronJob) error
AddJob registers a new job and starts scheduling it.
func (*CronScheduler) GetJob ¶
func (cs *CronScheduler) GetJob(id string) *CronJob
GetJob returns a job by ID, or nil if not found.
func (*CronScheduler) ListJobs ¶
func (cs *CronScheduler) ListJobs() []*CronJob
ListJobs returns all jobs from the store.
func (*CronScheduler) ListRuns ¶
func (cs *CronScheduler) ListRuns(jobID string) []*CronRun
ListRuns returns all runs for a job from the RunsStore.
func (*CronScheduler) PauseJob ¶
func (cs *CronScheduler) PauseJob(id string) error
PauseJob disables a job without removing it.
func (*CronScheduler) RemoveJob ¶
func (cs *CronScheduler) RemoveJob(id string) error
RemoveJob stops and deletes a job.
func (*CronScheduler) ResumeJob ¶
func (cs *CronScheduler) ResumeJob(id string) error
ResumeJob re-enables a paused job.
func (*CronScheduler) SetRunsStore ¶
func (cs *CronScheduler) SetRunsStore(rs *RunsStore)
SetRunsStore injects the RunsStore after construction.
func (*CronScheduler) Start ¶
func (cs *CronScheduler) Start() error
Start registers all enabled jobs and begins scheduling.
func (*CronScheduler) Stop ¶
func (cs *CronScheduler) Stop() context.Context
Stop gracefully stops the scheduler.
type CronStore ¶
type CronStore struct {
// contains filtered or unexported fields
}
CronStore persists CronJobs to disk using atomic writes (Mutex + os.Rename).
func NewCronStore ¶
NewCronStore loads or creates a CronStore at the given path.
type ExecuteRequest ¶
ExecuteRequest is the input for a cron job execution.
type ExecuteResult ¶
ExecuteResult is the output of a cron job execution.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor runs cron jobs via the SessionManager.
func NewExecutor ¶
func NewExecutor(manager intengine.SessionManager) *Executor
NewExecutor creates an Executor backed by a SessionManager.
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, req *ExecuteRequest) *ExecuteResult
Execute runs the job prompt via the SessionManager.
type OutputFormat ¶
type OutputFormat string
OutputFormat specifies how the job output should be formatted.
const ( OutputFormatText OutputFormat = "text" OutputFormatJSON OutputFormat = "json" OutputFormatStructured OutputFormat = "structured" )
type RunsStore ¶
type RunsStore struct {
// contains filtered or unexported fields
}
RunsStore persists CronRun records to runs.json with a per-job retention limit.
func NewRunsStore ¶
NewRunsStore loads or creates a RunsStore at dataDir/runs.json.
type WebhookCallback ¶
WebhookCallback calls a remote URL on job completion or failure.
func (*WebhookCallback) OnComplete ¶
func (wc *WebhookCallback) OnComplete(run *CronRun) error
func (*WebhookCallback) OnFail ¶
func (wc *WebhookCallback) OnFail(run *CronRun) error