Documentation ¶
Index ¶
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.
type Fixed ¶
type Fixed struct {
// contains filtered or unexported fields
}
Fixed A Timer that fires at a fixed duration intervals
type Logger ¶
type Logger interface { Debugw(msg string, keysAndValues ...interface{}) Errorw(msg string, keysAndValues ...interface{}) Fatalw(msg string, keysAndValues ...interface{}) Infow(msg string, keysAndValues ...interface{}) Panicw(msg string, keysAndValues ...interface{}) Warnw(msg string, keysAndValues ...interface{}) With(args ...interface{}) Logger Named(name string) Logger Sync() error }
Logger Sched logging interface similar to uber-go/zap, while keeping the option to change the logging implementation It is a sub-interface of uber-go/zap SugaredLogger.
func DefaultLogger ¶
func DefaultLogger() Logger
DefaultLogger Return Default Sched Logger based on Zap's sugared logger
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.
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 WithConsoleMetrics ¶
WithConsoleMetrics a predefined console metrics reporter, uses the Logger interface of the schedule to print out metrics logs.
func WithExpectedRunTime ¶
WithExpectedRunTime Use to indicate the expected Runtime ( Logs a warning and adds in metrics when it exceeds )
func WithLogger ¶
WithLogger Use the supplied Logger as the logger.
func WithMetrics ¶
WithMetrics Supply a tally.Scope to expose schedule metrics with. Ex. uber-go/tally/prometheus scope to expose schedule metrics via Prometheus endpoint. Use WithConsoleMetrics() to supply a predefined metrics console reporter without the need to implement any special metrics reporter scope.
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule A Schedule 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 ¶
NewSchedule Create a new schedule for` jobFunc func()` that will run according to `timer Timer` with the supplied []Options
func (*Schedule) Finish ¶
func (s *Schedule) Finish()
Finish stops the scheduler and put it FINISHED state so that schedule cannot re-start again. Finish() is called automatically if Schedule Timer returned `done bool` == true. Method is **Blocking** and concurrent safe.
func (*Schedule) Start ¶
func (s *Schedule) 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. STARTED: No Effect (and prints warning) 3. STOPPED: Restart the schedule 4. FINISHED: No Effect (and prints warning)
func (*Schedule) Stop ¶
func (s *Schedule) 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
- STARTED: Stop Schedule
- STOPPED: No Effect
- FINISHED: No Effect
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 ¶
Add Create a new schedule for` jobFunc func()` that will run according to `timer Timer` with the []Options of 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 State ¶
type State int64
State Indicate the state of the Schedule
const ( //NEW Schedule has just been created and hasn't started before NEW State = iota // STARTED Start Schedule has started and is running. STARTED // STOPPING Schedule is Stopping and is waiting for all active jobs to finish. STOPPING // STOPPED Schedule has stopped and no longer scheduling new Jobs. STOPPED // FINISHED Schedule has finished, and will not be able to start again. FINISHED )
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.