Documentation ¶
Index ¶
- Constants
- Variables
- type CronTrigger
- type Handler
- type HandlerFunc
- type IdleFunc
- type IdleHandler
- type Job
- func (job *Job) Cancel()
- func (job *Job) CheckTimeout() bool
- func (job *Job) Execute() (interface{}, error)
- func (job *Job) GetId() string
- func (job *Job) GetPayload() interface{}
- func (job *Job) GetState() State
- func (job *Job) GetType() string
- func (job *Job) IsQuit() bool
- func (job *Job) Pause()
- func (job *Job) SetHandler(fn Handler) *Job
- func (job *Job) SetResultHandler(fn ResultHandler) *Job
- func (job *Job) Start()
- func (job *Job) WithDelay(delay time.Duration) *Job
- func (job *Job) WithHandlerFunc(fn func(job *Job) (interface{}, error)) *Job
- func (job *Job) WithPayload(payload interface{}) *Job
- func (job *Job) WithResultFunc(fn func(res *Result)) *Job
- func (job *Job) WithTimeOut(timeout time.Duration) *Job
- type OnceTrigger
- type Pool
- type Result
- type ResultFunc
- type ResultHandler
- type ScheduledJob
- type Scheduler
- func (sched *Scheduler) AddTask(task Task)
- func (sched *Scheduler) AddTriggerTask(task Task, trigger Trigger) error
- func (sched *Scheduler) HasTask(schedId string) bool
- func (sched *Scheduler) RemoveTask(schedId string)
- func (sched *Scheduler) Run()
- func (sched *Scheduler) StopTask(schedId string)
- func (sched *Scheduler) UpdateTask(schedId string, update func(task Task) bool) bool
- type SimpleTrigger
- type State
- type Task
- type Trigger
Constants ¶
Variables ¶
var ErrJobFuncNil = result.Error(result.ErrParam, "job func is nil")
var ErrJobQuited = result.Error(result.ErrParam, "job quited")
Functions ¶
This section is empty.
Types ¶
type CronTrigger ¶
type CronTrigger struct {
// contains filtered or unexported fields
}
CronTrigger implements Examples: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html {秒数} {分钟} {小时} {日期} {月份} {星期} 1 Seconds (0-59) 2 Minutes (0-59) 3 Hours (0-23) 4 Day-of-Month (1-31) 5 Month (0-11) 6 Day-of-Week(1-7) 7 Year (optional field)
每个符号的意义 * 表示所有值; ? 表示未说明的值,即不关心它为何值; - 表示一个指定的范围; , 表示附加一个可能值; / 符号前表示开始时间,符号后表示每次递增的值
一些cron表达式案例 */5 * * * * ? 每隔5秒执行一次 0 */1 * * * ? 每隔1分钟执行一次 0 0 5-15 * * ? 每天5-15点整点触发 0 0/3 * * * ? 每三分钟触发一次 0 0-5 14 * * ? 在每天下午2点到下午2:05期间的每1分钟触发 0 0/5 14 * * ? 在每天下午2点到下午2:55期间的每5分钟触发 0 0/5 14,18 * * ? 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发 0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时 0 0 10,14,16 * * ? 每天上午10点,下午2点,4点 0 0 12 ? * WED 表示每个星期三中午12点 0 0 17 ? * TUES,THUR,SAT 每周二、四、六下午五点 0 10,44 14 ? 3 WED 每年三月的星期三的下午2:10和2:44触发 0 15 10 ? * MON-FRI 周一至周五的上午10:15触发 0 0 23 L * ? 每月最后一天23点执行一次 0 15 10 L * ? 每月最后一日的上午10:15触发 0 15 10 ? * 6L 每月的最后一个星期五上午10:15触发 0 15 10 * * ? 2005 2005年的每天上午10:15触发 0 15 10 ? * 6L 2002-2005 2002年至2005年的每月的最后一个星期五上午10:15触发 0 15 10 ? * 6#3 每月的第三个星期五上午10:15触发
"30 * * * * ?" 每半分钟触发任务 "30 10 * * * ?" 每小时的10分30秒触发任务 "30 10 1 * * ?" 每天1点10分30秒触发任务 "30 10 1 20 * ?" 每月20号1点10分30秒触发任务 "30 10 1 20 10 ? *" 每年10月20号1点10分30秒触发任务 "30 10 1 20 10 ? 2011" 2011年10月20号1点10分30秒触发任务 "30 10 1 ? 10 * 2011" 2011年10月每天1点10分30秒触发任务 "30 10 1 ? 10 SUN 2011" 2011年10月每周日1点10分30秒触发任务 "15,30,45 * * * * ?" 每15秒,30秒,45秒时触发任务 "15-45 * * * * ?" 15到45秒内,每秒都触发任务 "15/5 * * * * ?" 每分钟的每15秒开始触发,每隔5秒触发一次 "15-30/5 * * * * ?" 每分钟的15秒到30秒之间开始触发,每隔5秒触发一次 "0 0/3 * * * ?" 每小时的第0分0秒开始,每三分钟触发一次 "0 15 10 ? * MON-FRI" 星期一到星期五的10点15分0秒触发任务 "0 15 10 L * ?" 每个月最后一天的10点15分0秒触发任务 "0 15 10 LW * ?" 每个月最后一个工作日的10点15分0秒触发任务 "0 15 10 ? * 5L" 每个月最后一个星期四的10点15分0秒触发任务 "0 15 10 ? * 5#3" 每个月第三周的星期四的10点15分0秒触发任务 五:表达式生成器 有很多的cron表达式在线生成器,这里给大家推荐几款 http://www.pdtools.net/tools/becron.jsp http://cron.qqe2.com/
func NewCronTrigger ¶
func NewCronTrigger(expr string) (*CronTrigger, error)
NewCronTrigger returns a new CronTrigger using the UTC 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.
func (*CronTrigger) Type ¶ added in v1.3.58
func (ct *CronTrigger) Type() string
func (*CronTrigger) WithLocation ¶
func (ct *CronTrigger) WithLocation(lc *time.Location) *CronTrigger
type HandlerFunc ¶ added in v1.8.5
func (HandlerFunc) ProcessJob ¶ added in v1.8.5
func (fn HandlerFunc) ProcessJob(job *Job) (interface{}, error)
type IdleHandler ¶ added in v1.8.5
type IdleHandler interface {
Idle(num int32)
}
type Job ¶
type Job struct { Type string Id string State State StartAt int64 Delay time.Duration //延后执行,卡住 Timeout time.Duration // contains filtered or unexported fields }
func NewEmptyJob ¶ added in v1.4.0
func NewEmptyJob(fn HandlerFunc) *Job
func NewShellJob ¶
func (*Job) CheckTimeout ¶
func (*Job) GetPayload ¶ added in v1.8.5
func (job *Job) GetPayload() interface{}
func (*Job) SetHandler ¶ added in v1.8.5
func (*Job) SetResultHandler ¶ added in v1.8.5
func (job *Job) SetResultHandler(fn ResultHandler) *Job
func (*Job) WithHandlerFunc ¶ added in v1.8.5
func (*Job) WithPayload ¶ added in v1.8.5
func (*Job) WithResultFunc ¶ added in v1.8.5
type OnceTrigger ¶
OnceTrigger implements the quartz.Trigger interface. This type of Trigger can only be fired once and will expire immediately.
func NewOnceTrigger ¶
func NewOnceTrigger(delay time.Duration) *OnceTrigger
NewOnceTrigger returns a new OnceTrigger with the given delay time.
func (*OnceTrigger) Description ¶
func (tr *OnceTrigger) Description() string
Description returns the description of the trigger.
func (*OnceTrigger) NextFireTime ¶
func (tr *OnceTrigger) NextFireTime(prev int64) (int64, error)
NextFireTime returns the next time at which the OnceTrigger is scheduled to fire. Sets expired to true afterwards.
func (*OnceTrigger) Type ¶ added in v1.3.58
func (tr *OnceTrigger) Type() string
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func (*Pool) HasWorking ¶ added in v1.2.5
func (*Pool) SetIdleHandler ¶ added in v1.8.5
func (p *Pool) SetIdleHandler(fn IdleHandler) *Pool
func (*Pool) WithIdleFunc ¶ added in v1.8.5
type ResultFunc ¶ added in v1.8.5
type ResultFunc func(res *Result)
func (ResultFunc) ResultJob ¶ added in v1.8.5
func (fn ResultFunc) ResultJob(res *Result)
type ResultHandler ¶ added in v1.8.5
type ResultHandler interface {
ResultJob(res *Result)
}
type ScheduledJob ¶
func (*ScheduledJob) GValue ¶
func (it *ScheduledJob) GValue() interface{}
GValue for implement queue.IPriority
func (*ScheduledJob) PValue ¶
func (it *ScheduledJob) PValue() int64
PValue for implement queue.IPriority
type Scheduler ¶ added in v1.5.8
type Scheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶ added in v1.5.8
func NewSchedulerCap ¶ added in v1.5.8
func (*Scheduler) AddTriggerTask ¶ added in v1.5.8
func (*Scheduler) RemoveTask ¶ added in v1.5.8
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.
func (*SimpleTrigger) Type ¶ added in v1.3.58
func (st *SimpleTrigger) Type() string
type Trigger ¶
type Trigger interface { Type() string // 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.