Documentation ¶
Index ¶
- type Cron
- type ExecutionMiddleWare
- type Fixed
- type MWResult
- type MWResult_Op
- type Once
- type Option
- type RetryMiddleware
- type RetryResult
- type RetryResult_Op
- type Scheduler
- func (s *Scheduler) Add(ctx context.Context, id string, timer Timer, job func(context.Context), ...) error
- func (s *Scheduler) GetAllSchedules() (map[string]*Task, error)
- func (s *Scheduler) GetSchedule(id string) (*Task, error)
- func (s *Scheduler) Start(id string) error
- func (s *Scheduler) StartAll()
- func (s *Scheduler) Stop(id string) error
- func (s *Scheduler) StopAll()
- type Task
- type Timer
- type UpdateSignalOp_Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron A Timer that fires at according to a cron expression. All expresion supported by `https://github.com/gorhill/cronexpr` are supported.
func NewCron ¶
NewCron returns a Timer that fires at according to a cron expression. All expresion supported by `https://github.com/gorhill/cronexpr` are supported.
func (*Cron) Reschedule ¶
type ExecutionMiddleWare ¶
type ExecutionMiddleWare interface { PreHandler(s *Task) (MWResult, error) PostHandler(s *Task, err error) MWResult Reset(s *Task) Initilize(s *Task) }
PreExecutionMiddleWare Interface for developing new Middleware Pre Executation Middleware is run before executing a job.
type Fixed ¶
type Fixed struct {
// contains filtered or unexported fields
}
Fixed A Timer that fires at a fixed duration intervals
func (*Fixed) Reschedule ¶
type MWResult ¶
type MWResult struct {
Result MWResult_Op
}
type MWResult_Op ¶
type MWResult_Op int
const ( MWResult_Cancel MWResult_Op = iota MWResult_Defer MWResult_NextMW )
type Once ¶
type Once struct {
// contains filtered or unexported fields
}
Once A timer that run ONCE after an optional specific delay.
func NewOnce ¶
NewOnce Return a timer that trigger ONCE after `d` delay as soon as Timer is inquired for the next Run. Delay = 0 means the Timer return now(), aka as soon as time is inquired.
func NewOnceTime ¶
NewOnceTime Return a timer that trigger ONCE at `t` time.Time. If `t` is in the past at inquery time, timer will NOT run.
func (*Once) Reschedule ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option to customize schedule behavior, check the sched.With*() functions that implement Option interface for the available options
func WithExecutationMiddleWare ¶
func WithExecutationMiddleWare(handler ExecutionMiddleWare) Option
func WithLogger ¶
WithLogger Use the supplied Logger as the logger.
func WithRetryMiddleWare ¶
func WithRetryMiddleWare(handler RetryMiddleware) Option
type RetryMiddleware ¶
type RetryResult ¶
type RetryResult struct { Result RetryResult_Op Delay time.Duration }
type RetryResult_Op ¶
type RetryResult_Op int
const ( RetryResult_Retry RetryResult_Op = iota RetryResult_NoRetry RetryResult_NextMW )
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manage one or more Schedule creating them using common options, enforcing unique IDs, and supply methods to Start / Stop all schedule(s).
func NewScheduler ¶
NewScheduler Creates new Scheduler, opt Options are applied to *every* schedule added and created by this scheduler.
func (*Scheduler) Add ¶
func (s *Scheduler) Add(ctx context.Context, id string, timer Timer, job func(context.Context), extraOpts ...Option) error
Add Create a new Task for` jobFunc func()` that will run according to `timer Timer` with the []Options of the Scheduler.
func (*Scheduler) GetAllSchedules ¶
GetAllSchedules Returns all Schedule's in the Scheduler
func (*Scheduler) GetSchedule ¶
GetSchedule Returns a Schedule by ID from the Scheduler
func (*Scheduler) Start ¶
Start Start the Schedule with the given id. Return error if no Schedule with the given id exist.
func (*Scheduler) StartAll ¶
func (s *Scheduler) StartAll()
StartAll Start All Schedules managed by the Scheduler
type Task ¶
type Task struct { // Logging Interface Logger logr.Logger // Context for Jobs Ctx context.Context // contains filtered or unexported fields }
Task A Task is an object that wraps a Job (func(){}) and runs it on a schedule according to the supplied Timer; With the the ability to expose metrics, and write logs to indicate job health, state, and stats.
func NewSchedule ¶
func NewSchedule(ctx context.Context, id string, timer Timer, jobFunc func(context.Context), opts ...Option) *Task
NewSchedule Create a new schedule for` jobFunc func()` that will run according to `timer Timer` with the supplied []Options
func (*Task) GetNextRun ¶
func (*Task) Start ¶
func (s *Task) Start()
Start Start the scheduler. Method is concurrent safe. Calling Start() have the following effects according to the
scheduler state: 1. NEW: Start the Schedule; running the defined Job on the first Timer's Next() time. 2. QUEUED: No Effect (and prints warning) 3. STOPPED: Restart the schedule 4. FINISHED: No Effect (and prints warning)
func (*Task) Stop ¶
func (s *Task) Stop()
Stop stops the scheduler. Method is **Blocking** and concurrent safe. When called:
- Schedule will cancel all waiting scheduled jobs.
- Schedule will wait for all running jobs to finish. Calling Stop() has the following effects depending on the state of the schedule:
- NEW: No Effect
- QUEUED: Stop Schedule
- STOPPED: No Effect
- FINISHED: No Effect
type Timer ¶
Timer is an Interface for a Timer object that is used by a Schedule to determine when to run the next run of a job. Timer need to implement the Next() method returning the time of the next Job run. Timer indicates that no jobs shall be scheduled anymore by returning done == true. The `next time.Time` returned with `done bool` == true IS IGNORED. Next() shall not return time in the past. Time in the past is reset to time.Now() at evaluation time in the scheduler.
type UpdateSignalOp_Type ¶
type UpdateSignalOp_Type int