scheduler

package
v1.20.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Zlib Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	InitState      = State(0)
	RunningState   = State(1)
	PauseState     = State(2)
	CancelState    = State(3)
	CompletedState = State(4)
	TimeoutState   = State(5)
	ErrorState     = State(6)
)

Variables

View Source
var ErrJobFuncNil = result.Error(result.ErrParam, "job func is nil")
View Source
var ErrJobQuited = result.Error(result.ErrParam, "job quited")

Functions

func WithTaskDuration added in v1.20.24

func WithTaskDuration(t time.Duration) option.Option

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 Handler added in v1.8.5

type Handler interface {
	ProcessJob(job *Job) (interface{}, error)
}

type HandlerFunc added in v1.8.5

type HandlerFunc func(job *Job) (interface{}, error)

func (HandlerFunc) ProcessJob added in v1.8.5

func (fn HandlerFunc) ProcessJob(job *Job) (interface{}, error)

type IdleFunc added in v1.8.5

type IdleFunc func(num int32)

IdleFunc idle working number

func (IdleFunc) Idle added in v1.8.5

func (fn IdleFunc) Idle(num int32)

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 BuildJob added in v1.0.59

func BuildJob(jobType, jobId string, timeout time.Duration) Job

func NewEmptyJob added in v1.4.0

func NewEmptyJob(fn HandlerFunc) *Job

func NewJob

func NewJob(jobType, jobId string, timeout time.Duration) *Job

func NewShellJob

func NewShellJob(cmd string) *Job

func (*Job) Cancel

func (job *Job) Cancel()

func (*Job) CheckTimeout

func (job *Job) CheckTimeout() bool

func (*Job) Execute

func (job *Job) Execute() (interface{}, error)

func (*Job) GetId added in v1.5.8

func (job *Job) GetId() string

func (*Job) GetPayload added in v1.8.5

func (job *Job) GetPayload() interface{}

func (*Job) GetState

func (job *Job) GetState() State

func (*Job) GetType added in v1.3.58

func (job *Job) GetType() string

func (*Job) IsQuit

func (job *Job) IsQuit() bool

func (*Job) Pause

func (job *Job) Pause()

func (*Job) SetHandler added in v1.8.5

func (job *Job) SetHandler(fn Handler) *Job

func (*Job) SetResultHandler added in v1.8.5

func (job *Job) SetResultHandler(fn ResultHandler) *Job

func (*Job) Start

func (job *Job) Start()

func (*Job) WithDelay added in v1.9.8

func (job *Job) WithDelay(delay time.Duration) *Job

func (*Job) WithHandlerFunc added in v1.8.5

func (job *Job) WithHandlerFunc(fn func(job *Job) (interface{}, error)) *Job

func (*Job) WithPayload added in v1.8.5

func (job *Job) WithPayload(payload interface{}) *Job

func (*Job) WithResultFunc added in v1.8.5

func (job *Job) WithResultFunc(fn func(res *Result)) *Job

func (*Job) WithTimeOut

func (job *Job) WithTimeOut(timeout time.Duration) *Job

type OnceTrigger

type OnceTrigger struct {
	Delay time.Duration
	// contains filtered or unexported fields
}

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 NewPool

func NewPool(numWorkers, jobQueueLen int) *Pool

func (*Pool) AddJob added in v1.3.59

func (p *Pool) AddJob(job *Job)

func (*Pool) HasWorking added in v1.2.5

func (p *Pool) HasWorking() bool

func (*Pool) Release

func (p *Pool) Release()

func (*Pool) Run added in v1.3.59

func (p *Pool) Run()

func (*Pool) SetIdleHandler added in v1.8.5

func (p *Pool) SetIdleHandler(fn IdleHandler) *Pool

func (*Pool) WithIdleFunc added in v1.8.5

func (p *Pool) WithIdleFunc(fn func(num int32)) *Pool

type Result added in v1.8.5

type Result struct {
	Type string      `json:"type"`
	Id   string      `json:"id"`
	Err  error       `json:"err,omitempty"`
	Data interface{} `json:"data,omitempty"` //处理结果
}

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

type ScheduledJob struct {
	Trigger     Trigger
	Job         Task
	JobPriority int64
	NextRunTime int64
}

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 Instance

func Instance(opts ...option.Option) *Scheduler

func NewScheduler added in v1.5.8

func NewScheduler(groupNum uint32, opts ...option.Option) *Scheduler

func NewSchedulerCap added in v1.5.8

func NewSchedulerCap(groupNum uint32, capacity int, opts ...option.Option) *Scheduler

func (*Scheduler) AddTask added in v1.5.8

func (sched *Scheduler) AddTask(task Task)

func (*Scheduler) AddTriggerTask added in v1.5.8

func (sched *Scheduler) AddTriggerTask(task Task, trigger Trigger) error

func (*Scheduler) HasTask added in v1.5.8

func (sched *Scheduler) HasTask(schedId string) bool

func (*Scheduler) RemoveTask added in v1.5.8

func (sched *Scheduler) RemoveTask(schedId string)

func (*Scheduler) Run added in v1.5.8

func (sched *Scheduler) Run()

func (*Scheduler) StopTask added in v1.5.8

func (sched *Scheduler) StopTask(schedId string)

func (*Scheduler) UpdateTask added in v1.9.10

func (sched *Scheduler) UpdateTask(schedId string, update func(task Task) bool) bool

type SimpleTrigger

type SimpleTrigger struct {
	Interval time.Duration
}

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 State

type State int

func (State) Error

func (s State) Error() string

func (State) IsQuit

func (s State) IsQuit() bool

func (State) String

func (s State) String() string

type Task

type Task interface {
	GetType() string
	GetId() string
	GetState() State
	Execute() (interface{}, error)
	Cancel()
	Pause()
	Start()
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL