Documentation ¶
Overview ¶
Package quartz is a simple, zero-dependency scheduling library for Go. Inspired by the Quartz Java scheduler.
See README.md for more info.
Index ¶
- func HashCode(s string) int
- func NowNano() int64
- type CronExpressionParser
- type CronField
- type CronTrigger
- func (ct *CronTrigger) Day() []int
- func (ct *CronTrigger) DayOfWeek() []int
- func (ct *CronTrigger) Description() string
- func (ct *CronTrigger) ExpressionForHuman() string
- func (ct *CronTrigger) Hour() []int
- func (ct *CronTrigger) Minute() []int
- func (ct *CronTrigger) Month() []int
- func (ct *CronTrigger) NextFireTime(prev int64) (int64, error)
- func (ct *CronTrigger) Second() []int
- func (ct *CronTrigger) Year() []int
- type CurlJob
- type Item
- type Job
- type JobStatus
- type PriorityQueue
- type RunOnceTrigger
- type ScheduledJob
- type Scheduler
- type ShellJob
- type SimpleTrigger
- type StdScheduler
- func (sched *StdScheduler) Clear()
- func (sched *StdScheduler) DeleteJob(key int) error
- func (sched *StdScheduler) GetJobKeys() []int
- func (sched *StdScheduler) GetScheduledJob(key int) (*ScheduledJob, error)
- func (sched *StdScheduler) ScheduleJob(job Job, trigger Trigger) error
- func (sched *StdScheduler) Start()
- func (sched *StdScheduler) Stop()
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CronExpressionParser ¶
type CronExpressionParser struct {
// contains filtered or unexported fields
}
CronExpressionParser parses cron expressions.
func NewCronExpressionParser ¶
func NewCronExpressionParser(lastDefined int) *CronExpressionParser
NewCronExpressionParser returns a new CronExpressionParser.
type CronField ¶
type CronField struct {
// contains filtered or unexported fields
}
CronField represents a parsed cron expression as an array.
type CronTrigger ¶
type CronTrigger struct {
// contains filtered or unexported fields
}
CronTrigger implements the quartz.Trigger interface. Used to fire a Job at given moments in time, defined with Unix 'cron-like' schedule definitions.
Examples:
Expression Meaning "0 0 12 * * ?" Fire at 12pm (noon) every day "0 15 10 ? * *" Fire at 10:15am every day "0 15 10 * * ?" Fire at 10:15am every day "0 15 10 * * ? *" Fire at 10:15am every day "0 * 14 * * ?" Fire every minute starting at 2pm and ending at 2:59pm, every day "0 0/5 14 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day "0 0/5 14,18 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm,
AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
"0 0-5 14 * * ?" Fire every minute starting at 2pm and ending at 2:05pm, every day "0 10,44 14 ? 3 WED" Fire at 2:10pm and at 2:44pm every Wednesday in the month of March. "0 15 10 ? * MON-FRI" Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday "0 15 10 15 * ?" Fire at 10:15am on the 15th day of every month
func NewCronTrigger ¶
func NewCronTrigger(expr string) (*CronTrigger, error)
NewCronTrigger returns a new CronTrigger.
func (*CronTrigger) Day ¶
func (ct *CronTrigger) Day() []int
func (*CronTrigger) DayOfWeek ¶
func (ct *CronTrigger) DayOfWeek() []int
func (*CronTrigger) Description ¶
func (ct *CronTrigger) Description() string
Description returns a CronTrigger description.
func (*CronTrigger) ExpressionForHuman ¶
func (ct *CronTrigger) ExpressionForHuman() string
func (*CronTrigger) Hour ¶
func (ct *CronTrigger) Hour() []int
func (*CronTrigger) Minute ¶
func (ct *CronTrigger) Minute() []int
func (*CronTrigger) Month ¶
func (ct *CronTrigger) Month() []int
func (*CronTrigger) NextFireTime ¶
func (ct *CronTrigger) NextFireTime(prev int64) (int64, error)
NextFireTime returns the next time at which the CronTrigger is scheduled to fire.
func (*CronTrigger) Second ¶
func (ct *CronTrigger) Second() []int
func (*CronTrigger) Year ¶
func (ct *CronTrigger) Year() []int
type CurlJob ¶
type CurlJob struct { RequestMethod string URL string Body string Headers map[string]string Response string StatusCode int JobStatus JobStatus // contains filtered or unexported fields }
CurlJob is the curl command Job, implements the quartz.Job interface.
func NewCurlJob ¶
func NewCurlJob( method string, url string, body string, headers map[string]string, ) (*CurlJob, error)
NewCurlJob returns a new CurlJob.
func (*CurlJob) Description ¶
Description returns a CurlJob description.
type Job ¶
type Job interface { // Execute Called by the Scheduler when a Trigger fires that is associated with the Job. Execute() // Description returns a Job description. Description() string // Key returns a Job unique key. Key() int }
Job is the interface to be implemented by structs which represent a 'job' to be performed.
type PriorityQueue ¶
type PriorityQueue []*Item
PriorityQueue implements the heap.Interface.
func (*PriorityQueue) Head ¶
func (pq *PriorityQueue) Head() *Item
Head returns the first item of a PriorityQueue without removing it.
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
Less is the items less comparator.
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
Pop implements the heap.Interface.Pop. Removes and returns element Len() - 1.
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
Push implements the heap.Interface.Push. Adds x as element Len().
func (*PriorityQueue) Remove ¶
func (pq *PriorityQueue) Remove(i int) interface{}
Remove removes and returns the element at index i from the PriorityQueue.
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
Swap exchanges the indexes of the items.
type RunOnceTrigger ¶
RunOnceTrigger implements the quartz.Trigger interface. Could be triggered only once.
func NewRunOnceTrigger ¶
func NewRunOnceTrigger(delay time.Duration) *RunOnceTrigger
NewRunOnceTrigger returns a new RunOnceTrigger.
func (*RunOnceTrigger) Description ¶
func (st *RunOnceTrigger) Description() string
Description returns a RunOnceTrigger description.
func (*RunOnceTrigger) NextFireTime ¶
func (st *RunOnceTrigger) NextFireTime(prev int64) (int64, error)
NextFireTime returns the next time at which the RunOnceTrigger is scheduled to fire. Sets exprired to true afterwards.
type ScheduledJob ¶
ScheduledJob wraps the scheduled job with the metadata.
type Scheduler ¶
type Scheduler interface { // start the scheduler Start() // schedule the job with the specified trigger ScheduleJob(job Job, trigger Trigger) error // get keys of all of the scheduled jobs GetJobKeys() []int // get the scheduled job metadata GetScheduledJob(key int) (*ScheduledJob, error) // remove the job from the execution queue DeleteJob(key int) error // clear all the scheduled jobs Clear() // shutdown the scheduler Stop() }
A Scheduler is the Jobs orchestrator. Schedulers responsible for executing Jobs when their associated Triggers fire (when their scheduled time arrives).
type ShellJob ¶
ShellJob is the shell command Job, implements the quartz.Job interface. Consider the runtime.GOOS when sending the shell command to execute.
func (*ShellJob) Description ¶
Description returns a ShellJob description.
type SimpleTrigger ¶
SimpleTrigger implements the quartz.Trigger interface; uses a time.Duration interval.
func NewSimpleTrigger ¶
func NewSimpleTrigger(interval time.Duration) *SimpleTrigger
NewSimpleTrigger returns a new SimpleTrigger.
func (*SimpleTrigger) Description ¶
func (st *SimpleTrigger) Description() string
Description returns a SimpleTrigger description.
func (*SimpleTrigger) NextFireTime ¶
func (st *SimpleTrigger) NextFireTime(prev int64) (int64, error)
NextFireTime returns the next time at which the SimpleTrigger is scheduled to fire.
type StdScheduler ¶
type StdScheduler struct { sync.Mutex Queue *PriorityQueue // contains filtered or unexported fields }
StdScheduler implements the quartz.Scheduler interface.
func NewStdScheduler ¶
func NewStdScheduler() *StdScheduler
NewStdScheduler returns a new StdScheduler.
func (*StdScheduler) Clear ¶
func (sched *StdScheduler) Clear()
Clear removes all of the scheduled jobs.
func (*StdScheduler) DeleteJob ¶
func (sched *StdScheduler) DeleteJob(key int) error
DeleteJob removes the job for the specified key from the StdScheduler if present.
func (*StdScheduler) GetJobKeys ¶
func (sched *StdScheduler) GetJobKeys() []int
GetJobKeys returns the keys of all of the scheduled jobs.
func (*StdScheduler) GetScheduledJob ¶
func (sched *StdScheduler) GetScheduledJob(key int) (*ScheduledJob, error)
GetScheduledJob returns the ScheduledJob by the unique key.
func (*StdScheduler) ScheduleJob ¶
func (sched *StdScheduler) ScheduleJob(job Job, trigger Trigger) error
ScheduleJob uses the specified Trigger to schedule the Job.
func (*StdScheduler) Start ¶
func (sched *StdScheduler) Start()
Start starts the StdScheduler execution loop.
func (*StdScheduler) Stop ¶
func (sched *StdScheduler) Stop()
Stop exits the StdScheduler execution loop.
type Trigger ¶
type Trigger interface { // NextFireTime returns the next time at which the Trigger is scheduled to fire. NextFireTime(prev int64) (int64, error) // Description returns a Trigger description. Description() string }
Trigger is the Triggers interface. Triggers are the 'mechanism' by which Jobs are scheduled.