Documentation
¶
Index ¶
- func ValidateCron(expr string) error
- type CronScheduler
- func (s *CronScheduler) Create(job *ScheduledJob) error
- func (s *CronScheduler) Delete(id string) error
- func (s *CronScheduler) ExecuteNow(ctx context.Context, id string) (*ExecutionRecord, error)
- func (s *CronScheduler) Get(id string) (*ScheduledJob, bool)
- func (s *CronScheduler) History(jobID string) []*ExecutionRecord
- func (s *CronScheduler) List() []*ScheduledJob
- func (s *CronScheduler) NextRuns(cronExpr string, n int) ([]time.Time, error)
- func (s *CronScheduler) Pause(id string) error
- func (s *CronScheduler) Resume(id string) error
- func (s *CronScheduler) SetNextRunFunc(fn func(string, time.Time) (time.Time, error))
- func (s *CronScheduler) Update(id string, name, cronExpr, workflowType, action string, params map[string]any) error
- type ExecutionRecord
- type ExecutionStatus
- type Handler
- type JobStatus
- type ScheduledJob
- type WorkflowTrigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCron ¶
ValidateCron validates a standard 5-field cron expression.
Types ¶
type CronScheduler ¶
type CronScheduler struct {
// contains filtered or unexported fields
}
CronScheduler manages scheduled workflow executions.
func NewCronScheduler ¶
func NewCronScheduler(trigger WorkflowTrigger) *CronScheduler
NewCronScheduler creates a new CronScheduler.
func (*CronScheduler) Create ¶
func (s *CronScheduler) Create(job *ScheduledJob) error
Create adds a new scheduled job. It validates the cron expression and returns an error if invalid.
func (*CronScheduler) Delete ¶
func (s *CronScheduler) Delete(id string) error
Delete soft-deletes a job and stops its execution loop.
func (*CronScheduler) ExecuteNow ¶
func (s *CronScheduler) ExecuteNow(ctx context.Context, id string) (*ExecutionRecord, error)
ExecuteNow triggers immediate execution of a job (bypasses schedule).
func (*CronScheduler) Get ¶
func (s *CronScheduler) Get(id string) (*ScheduledJob, bool)
Get returns a job by ID.
func (*CronScheduler) History ¶
func (s *CronScheduler) History(jobID string) []*ExecutionRecord
History returns execution records for a job, newest first.
func (*CronScheduler) List ¶
func (s *CronScheduler) List() []*ScheduledJob
List returns all non-deleted jobs sorted by creation time.
func (*CronScheduler) NextRuns ¶
NextRuns returns up to n upcoming execution times for a given cron expression.
func (*CronScheduler) Resume ¶
func (s *CronScheduler) Resume(id string) error
Resume resumes a paused job.
func (*CronScheduler) SetNextRunFunc ¶
SetNextRunFunc allows overriding the next-run calculation (useful for testing).
type ExecutionRecord ¶
type ExecutionRecord struct {
ID string `json:"id"`
JobID string `json:"jobId"`
Status ExecutionStatus `json:"status"`
StartedAt time.Time `json:"startedAt"`
Duration time.Duration `json:"duration"`
Error string `json:"error,omitempty"`
}
ExecutionRecord records the result of a single job execution.
type ExecutionStatus ¶
type ExecutionStatus string
ExecutionStatus represents the result of a job execution.
const ( ExecStatusSuccess ExecutionStatus = "success" ExecStatusFailed ExecutionStatus = "failed" ExecStatusSkipped ExecutionStatus = "skipped" )
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP endpoints for scheduled job management.
func NewHandler ¶
func NewHandler(scheduler *CronScheduler) *Handler
NewHandler creates a new scheduler HTTP handler.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers scheduler API routes on the given mux.
type ScheduledJob ¶
type ScheduledJob struct {
ID string `json:"id"`
Name string `json:"name"`
CronExpr string `json:"cronExpr"`
WorkflowType string `json:"workflowType"`
Action string `json:"action"`
Params map[string]any `json:"params,omitempty"`
Status JobStatus `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
LastRunAt *time.Time `json:"lastRunAt,omitempty"`
NextRunAt *time.Time `json:"nextRunAt,omitempty"`
}
ScheduledJob represents a job that runs on a cron schedule.