Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
Executor describes the worker pool that receives jobs dispatched from Scheduler. Composing the Executor inside Scheduler will give the opportunity to a more plugable executors which mean User can write their own Executor algorithms.
func DefaultExecutor ¶
func NewExecutor ¶
type Job ¶
type Job struct { sync.RWMutex Name string Function interface{} Params []interface{} LastRun time.Time NextRun time.Time Count int // Number of times the Job ran NextDeadline time.Time // Next deadline for the Job to be running Timeout time.Duration // Max execution time to run the task Frequency time.Duration // Scheduling frequency that the job should be run with }
Job abstract Background job with its metadata This struct wraps the Function & Params with all the required Data to successfully run the Job in the background It also include locking to avoid updates while scheduling/running which will yield weird behavior only. Time and Frequencies are in seconds only. Adding duration formats will be fairly straight forward since we can abstract this detail later. But using "seconds" only will help simplify the scheduling algorithm
type Scheduler ¶
type Scheduler struct { ExecutorName *string IsRunning bool Jobs []*Job MetricsServer *http.Server // contains filtered or unexported fields }
Scheduler describe Scheduling API and dispatcher You can provide custom executor by setting `Executor` attribute inside scheduler config object `C` while calling `NewScheduler`
func NewScheduler ¶
NewScheduler create and return a new scheduler instance You can later start add tasks using `scheduler.Add(j *Job)` method This function also expose custom prometheus metrics using the `/$PORT/-/metrics` endpoint. By default $PORT=9091 but you can override that by passing the port as the first arg to the scheduler passed as a string
func (*Scheduler) CleanUp ¶
func (s *Scheduler) CleanUp()
CleanUp stops all running jobs, remove all scheduled jobs and stops metricsServer
func (*Scheduler) Start ¶
func (s *Scheduler) Start()
Start run the scheduler idempotently and block program execution by default. To run the scheduler in the background use StartAsync
func (*Scheduler) StartAsync ¶
func (s *Scheduler) StartAsync()
StartAsync run the scheduler in the background without blocking the main goroutine
func (*Scheduler) StopMetricsServer ¶
func (s *Scheduler) StopMetricsServer()
StopMetricsServer gracefully shut down running MetricsServer after 2 seconds