Documentation
¶
Index ¶
- func FormatDuration(d time.Duration) string
- func GetBackoffDelay(consecutiveErrors int) time.Duration
- func ParseHumanDuration(s string) (time.Duration, error)
- type CronConfig
- type Delivery
- type DeliveryMode
- type Job
- func (j *Job) CalculateNextRun(from time.Time) (time.Time, error)
- func (j *Job) IsOneShot() bool
- func (j *Job) IsRunning() bool
- func (j *Job) MarkCompleted(now time.Time, status string, errMsg string)
- func (j *Job) MarkRunning(now time.Time)
- func (j *Job) ShouldDisableOnComplete() bool
- func (j *Job) ShouldRun(now time.Time) bool
- type JobExecutor
- type JobState
- type Payload
- type PayloadType
- type RunLog
- type RunLogConfig
- type RunLogFilter
- type RunLogger
- type Schedule
- type ScheduleType
- type Service
- func (s *Service) AddJob(job *Job) error
- func (s *Service) DisableJob(id string) error
- func (s *Service) EnableJob(id string) error
- func (s *Service) GetJob(id string) (*Job, error)
- func (s *Service) GetRunLogs(jobID string, filter RunLogFilter) ([]*RunLog, error)
- func (s *Service) GetStatus() map[string]interface{}
- func (s *Service) ListJobs() []*Job
- func (s *Service) RemoveJob(id string) error
- func (s *Service) RunJob(ctx context.Context, id string, force bool) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop() error
- func (s *Service) UpdateJob(id string, update func(*Job) error) error
- type SessionTarget
- type Store
- type WakeMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶ added in v0.3.1
FormatDuration formats a duration in human-readable format
func GetBackoffDelay ¶ added in v0.3.1
GetBackoffDelay calculates exponential backoff delay for consecutive errors
Types ¶
type CronConfig ¶ added in v0.3.1
type CronConfig struct {
Enabled bool `json:"enabled"`
StorePath string `json:"store_path,omitempty"`
MaxConcurrentRuns int `json:"max_concurrent_runs,omitempty"`
SessionRetention time.Duration `json:"session_retention,omitempty"` // Session cleanup retention
RunLogConfig RunLogConfig `json:"run_log_config"`
DefaultTimeout time.Duration `json:"default_timeout"` // Default job timeout
}
CronConfig represents cron configuration
func DefaultCronConfig ¶ added in v0.3.1
func DefaultCronConfig() CronConfig
DefaultCronConfig returns default cron configuration
type Delivery ¶ added in v0.3.1
type Delivery struct {
Mode DeliveryMode `json:"mode"`
WebhookURL string `json:"webhook_url,omitempty"`
WebhookToken string `json:"webhook_token,omitempty"`
BestEffort bool `json:"best_effort,omitempty"` // Don't fail job on delivery error
}
Delivery configuration
type DeliveryMode ¶ added in v0.3.1
type DeliveryMode string
DeliveryMode defines how job results are delivered
const ( DeliveryModeAnnounce DeliveryMode = "announce" // Send to chat channels DeliveryModeWebhook DeliveryMode = "webhook" // HTTP POST to URL DeliveryModeNone DeliveryMode = "none" // No delivery )
type Job ¶
type Job struct {
ID string `json:"id"`
Name string `json:"name"`
Schedule Schedule `json:"schedule"`
SessionTarget SessionTarget `json:"session_target"`
WakeMode WakeMode `json:"wake_mode"`
Payload Payload `json:"payload"`
Delivery *Delivery `json:"delivery,omitempty"`
State JobState `json:"state"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Job represents a scheduled cron job
func (*Job) CalculateNextRun ¶ added in v0.3.1
CalculateNextRun calculates the next run time based on schedule
func (*Job) MarkCompleted ¶ added in v0.3.1
MarkCompleted marks the job as completed with a status
func (*Job) MarkRunning ¶ added in v0.3.1
MarkRunning marks the job as running
func (*Job) ShouldDisableOnComplete ¶ added in v0.3.1
ShouldDisableOnComplete returns true if job should be disabled after terminal status
type JobExecutor ¶ added in v0.3.1
type JobExecutor struct {
// contains filtered or unexported fields
}
JobExecutor handles execution of cron jobs
func NewJobExecutor ¶ added in v0.3.1
func NewJobExecutor(bus *bus.MessageBus, runLogger *RunLogger, timeout time.Duration) *JobExecutor
NewJobExecutor creates a new job executor
type JobState ¶ added in v0.3.1
type JobState struct {
Enabled bool `json:"enabled"`
RunningAt *time.Time `json:"running_at,omitempty"` // Set when job is running
LastRunAt *time.Time `json:"last_run_at,omitempty"` // Last successful run
NextRunAt *time.Time `json:"next_run_at,omitempty"` // Next scheduled run
ConsecutiveErrors int `json:"consecutive_errors"` // Count of consecutive errors
RunCount int `json:"run_count"` // Total successful runs
ErrorBackoffUntil *time.Time `json:"error_backoff_until,omitempty"` // Backoff for failed jobs
LastStatus string `json:"last_status"` // Last run status: "ok", "error", "skipped"
LastError string `json:"last_error,omitempty"` // Last error message
}
JobState represents the current state of a job
type Payload ¶ added in v0.3.1
type Payload struct {
Type PayloadType `json:"type"`
// For system-event type
SystemEventType string `json:"system_event_type,omitempty"`
// For agent-turn type
Message string `json:"message,omitempty"`
}
Payload defines what the job executes
type PayloadType ¶ added in v0.3.1
type PayloadType string
PayloadType defines the job payload type
const ( PayloadTypeSystemEvent PayloadType = "system-event" PayloadTypeAgentTurn PayloadType = "agent-turn" )
type RunLog ¶ added in v0.3.1
type RunLog struct {
RunID string `json:"run_id"`
JobID string `json:"job_id"`
JobName string `json:"job_name"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
Status string `json:"status"` // "ok", "error", "skipped"
Error string `json:"error,omitempty"`
Duration time.Duration `json:"duration"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Additional telemetry
Timestamp time.Time `json:"timestamp"`
}
RunLog represents a single run of a job
type RunLogConfig ¶ added in v0.3.1
type RunLogConfig struct {
MaxBytes int64 `json:"max_bytes,omitempty"` // Max file size before rotation
KeepLines int `json:"keep_lines,omitempty"` // Max lines to keep per job
}
RunLogConfig represents run log configuration
type RunLogFilter ¶ added in v0.3.1
type RunLogFilter struct {
JobID string `json:"job_id,omitempty"`
After time.Time `json:"after,omitempty"`
Before time.Time `json:"before,omitempty"`
Status string `json:"status,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
RunLogFilter defines filters for querying run logs
type RunLogger ¶ added in v0.3.1
type RunLogger struct {
// contains filtered or unexported fields
}
RunLogger handles logging of job runs
func NewRunLogger ¶ added in v0.3.1
func NewRunLogger(logDir string, config RunLogConfig) (*RunLogger, error)
NewRunLogger creates a new run logger
func (*RunLogger) DeleteJobLogs ¶ added in v0.3.1
DeleteJobLogs removes all logs for a job
type Schedule ¶
type Schedule struct {
Type ScheduleType `json:"type"`
// For "at" type
At time.Time `json:"at,omitempty"`
// For "every" type
EveryDuration time.Duration `json:"every_duration,omitempty"`
// For "cron" type
CronExpression string `json:"cron_expression,omitempty"`
Timezone string `json:"timezone,omitempty"`
// Stagger support (for load distribution)
StaggerDuration time.Duration `json:"stagger_duration,omitempty"`
}
Schedule defines when a job should run
func (Schedule) MarshalJSON ¶ added in v0.3.1
MarshalJSON implements custom JSON marshaling for Schedule
func (*Schedule) UnmarshalJSON ¶ added in v0.3.1
UnmarshalJSON implements custom JSON unmarshaling for Schedule
type ScheduleType ¶ added in v0.3.1
type ScheduleType string
ScheduleType represents the type of schedule
const ( ScheduleTypeAt ScheduleType = "at" // One-shot at specific time ScheduleTypeEvery ScheduleType = "every" // Fixed interval ScheduleTypeCron ScheduleType = "cron" // Cron expression )
type Service ¶ added in v0.3.1
type Service struct {
// contains filtered or unexported fields
}
Service manages cron jobs
func NewService ¶ added in v0.3.1
func NewService(config CronConfig, bus *bus.MessageBus) (*Service, error)
NewService creates a new cron service
func (*Service) DisableJob ¶ added in v0.3.1
DisableJob disables a job
func (*Service) GetRunLogs ¶ added in v0.3.1
func (s *Service) GetRunLogs(jobID string, filter RunLogFilter) ([]*RunLog, error)
GetRunLogs retrieves run logs for a job
func (*Service) GetStatus ¶ added in v0.3.1
GetStatus returns the current status of the cron service
type SessionTarget ¶ added in v0.3.1
type SessionTarget string
SessionTarget defines where the job runs
const ( SessionTargetMain SessionTarget = "main" // Run in main session SessionTargetIsolated SessionTarget = "isolated" // Run in dedicated isolated session )