Documentation
¶
Index ¶
- type CronScheduler
- func (s *CronScheduler) ListJobs() []string
- func (s *CronScheduler) RunNow(ctx context.Context, jobName string) error
- func (s *CronScheduler) Schedule(schedule Schedule, job Job) error
- func (s *CronScheduler) ScheduleCron(cronExpr string, job Job) error
- func (s *CronScheduler) Start()
- func (s *CronScheduler) Stop() context.Context
- type Job
- type Schedule
- type Scheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CronScheduler ¶
type CronScheduler struct {
// contains filtered or unexported fields
}
CronScheduler implements Scheduler using robfig/cron
func NewCronScheduler ¶
func NewCronScheduler(logger *zap.SugaredLogger) *CronScheduler
NewCronScheduler creates a new cron-based scheduler
func (*CronScheduler) ListJobs ¶
func (s *CronScheduler) ListJobs() []string
ListJobs returns all registered job names
func (*CronScheduler) RunNow ¶
func (s *CronScheduler) RunNow(ctx context.Context, jobName string) error
RunNow executes a job immediately by name
func (*CronScheduler) Schedule ¶
func (s *CronScheduler) Schedule(schedule Schedule, job Job) error
Schedule adds a job to run on the given schedule
func (*CronScheduler) ScheduleCron ¶
func (s *CronScheduler) ScheduleCron(cronExpr string, job Job) error
ScheduleCron adds a job with a custom cron expression Cron format: second minute hour day month weekday (6 fields with seconds support) Examples:
"0 0 * * * *" - Every hour at minute 0 "0 */5 * * * *" - Every 5 minutes "0 0 0 * * *" - Every day at midnight "@hourly" - Every hour (equivalent to "0 0 * * * *")
func (*CronScheduler) Start ¶
func (s *CronScheduler) Start()
Start begins processing scheduled jobs
func (*CronScheduler) Stop ¶
func (s *CronScheduler) Stop() context.Context
Stop gracefully stops the scheduler
type Job ¶
type Job interface {
// Name returns the unique name of the job
Name() string
// Execute runs the job
Execute(ctx context.Context) error
}
Job represents a scheduled job that can be executed
type Schedule ¶
type Schedule string
Schedule represents when a job should run
const ( // ScheduleDaily runs the job once per day at midnight UTC ScheduleDaily Schedule = "@daily" // ScheduleWeekly runs the job once per week on Sunday at midnight UTC ScheduleWeekly Schedule = "@weekly" // ScheduleMonthly runs the job once per month on the 1st at midnight UTC ScheduleMonthly Schedule = "@monthly" )
type Scheduler ¶
type Scheduler interface {
// Schedule adds a job to run on the given schedule
Schedule(schedule Schedule, job Job) error
// ScheduleCron adds a job with a custom cron expression
ScheduleCron(cronExpr string, job Job) error
// Start begins processing scheduled jobs
Start()
// Stop gracefully stops the scheduler
Stop() context.Context
// RunNow executes a job immediately by name (useful for testing/manual triggers)
RunNow(ctx context.Context, jobName string) error
// ListJobs returns all registered job names
ListJobs() []string
}
Scheduler is the interface for scheduling and managing jobs This abstraction allows swapping the underlying scheduler implementation (e.g., from built-in cron to an external scheduler like Temporal or a message queue)