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
- 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) IsStarted() bool
- 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 using the UTC location.
func NewCronTriggerWithLoc ¶ added in v0.4.1
func NewCronTriggerWithLoc(expr string, location *time.Location) (*CronTrigger, error)
NewCronTriggerWithLoc returns a new CronTrigger with the given time.Location.
func (*CronTrigger) Description ¶
func (ct *CronTrigger) Description() string
Description returns the description of the trigger.
func (*CronTrigger) NextFireTime ¶
func (ct *CronTrigger) NextFireTime(prev int64) (int64, error)
NextFireTime returns the next time at which the CronTrigger is scheduled to fire.
type CurlJob ¶ added in v0.3.0
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 represents a cURL command Job, implements the quartz.Job interface. cURL is a command-line tool for getting or sending data including files using URL syntax.
func NewCurlJob ¶ added in v0.3.0
func NewCurlJob( method string, url string, body string, headers map[string]string, ) (*CurlJob, error)
NewCurlJob returns a new CurlJob.
func (*CurlJob) Description ¶ added in v0.3.0
Description returns the description of the CurlJob.
type Job ¶
type Job interface { // Execute is called by a Scheduler when the Trigger associated with this job fires. Execute() // Description returns the description of the Job. Description() string // Key returns the unique key for the Job. Key() int }
Job represents an 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 ¶ added in v0.4.1
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. This type of Trigger can only be fired once and will expire immediately.
func NewRunOnceTrigger ¶
func NewRunOnceTrigger(delay time.Duration) *RunOnceTrigger
NewRunOnceTrigger returns a new RunOnceTrigger with the given delay time.
func (*RunOnceTrigger) Description ¶
func (ot *RunOnceTrigger) Description() string
Description returns the description of the trigger.
func (*RunOnceTrigger) NextFireTime ¶
func (ot *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 a scheduled Job with its metadata.
type Scheduler ¶
type Scheduler interface { // Start starts the scheduler. Start() // IsStarted determines whether the scheduler has been started. IsStarted() bool // ScheduleJob schedules a job using a specified trigger. ScheduleJob(job Job, trigger Trigger) error // GetJobKeys returns the keys of all of the scheduled jobs. GetJobKeys() []int // GetScheduledJob returns the scheduled job with the specified key. GetScheduledJob(key int) (*ScheduledJob, error) // DeleteJob removes the job with the specified key from the Scheduler's execution queue. DeleteJob(key int) error // Clear removes all of the scheduled jobs. Clear() // Stop shutdowns the scheduler. Stop() }
Scheduler represents a Job orchestrator. Schedulers are responsible for executing Jobs when their associated Triggers fire (when their scheduled time arrives).
type ShellJob ¶ added in v0.3.0
ShellJob represents a shell command Job, implements the quartz.Job interface. Be aware of runtime.GOOS when sending shell commands for execution.
func NewShellJob ¶ added in v0.3.0
NewShellJob returns a new ShellJob.
func (*ShellJob) Description ¶ added in v0.3.0
Description returns the description of the ShellJob.
type SimpleTrigger ¶
SimpleTrigger implements the quartz.Trigger interface; uses a fixed interval.
func NewSimpleTrigger ¶
func NewSimpleTrigger(interval time.Duration) *SimpleTrigger
NewSimpleTrigger returns a new SimpleTrigger using the given interval.
func (*SimpleTrigger) Description ¶
func (st *SimpleTrigger) Description() string
Description returns the description of the trigger.
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 with the specified key 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 with the specified key.
func (*StdScheduler) IsStarted ¶ added in v0.4.1
func (sched *StdScheduler) IsStarted() bool
IsStarted determines whether the scheduler has been started.
func (*StdScheduler) ScheduleJob ¶
func (sched *StdScheduler) ScheduleJob(job Job, trigger Trigger) error
ScheduleJob schedules a Job using a specified Trigger.
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 the description of the Trigger. Description() string }
Trigger represents the mechanism by which Jobs are scheduled.