scheduler

package
v1.0.64 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: Zlib Imports: 10 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

This section is empty.

Functions

func SetInstance

func SetInstance(tasks *Tasks)

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) WithLocation

func (ct *CronTrigger) WithLocation(lc *time.Location) *CronTrigger

type Job

type Job struct {
	JId      string
	JState   State
	JFunc    JobFunc
	JTimeout time.Duration
	JStartAt int64
}

func BuildJob added in v1.0.59

func BuildJob(jobId string) Job

func NewJob

func NewJob(jobId string) *Job

func (*Job) Cancel

func (job *Job) Cancel()

func (*Job) CheckTimeout

func (job *Job) CheckTimeout() bool

func (*Job) Execute

func (job *Job) Execute() State

func (*Job) GetKey

func (job *Job) GetKey() string

func (*Job) GetState

func (job *Job) GetState() State

func (*Job) IsQuit

func (job *Job) IsQuit() bool

func (*Job) Pause

func (job *Job) Pause()

func (*Job) Start

func (job *Job) Start()

func (*Job) WithCall

func (job *Job) WithCall(fn JobFunc) *Job

func (*Job) WithTimeOut

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

type JobFunc

type JobFunc func() (interface{}, error)

type JobResult

type JobResult struct {
	JId    string
	Result interface{}
	Err    error
}

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 (ot *OnceTrigger) Description() string

Description returns the description of the trigger.

func (*OnceTrigger) NextFireTime

func (ot *OnceTrigger) NextFireTime(prev int64) (int64, error)

NextFireTime returns the next time at which the OnceTrigger is scheduled to fire. Sets exprired to true afterwards.

type Pool

type Pool struct {
	JobQueue  chan Job
	JobResult chan JobResult
	// contains filtered or unexported fields
}

func NewPool

func NewPool(numWorkers int, jobQueueLen int) *Pool

func (*Pool) JobDone

func (p *Pool) JobDone()

func (*Pool) Release

func (p *Pool) Release()

func (*Pool) WaitAll

func (p *Pool) WaitAll()

func (*Pool) WaitCount

func (p *Pool) WaitCount(count int)

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.IPriorityItem

func (*ScheduledJob) PValue

func (it *ScheduledJob) PValue() int64

PValue for implement queue.IPriorityItem

type ShellJob

type ShellJob struct {
	Job
	Cmd    string
	Result system.ExecResult
}

func NewShellJob

func NewShellJob(cmd string) *ShellJob

func (*ShellJob) Execute

func (job *ShellJob) Execute() State

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.

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 {
	GetKey() string
	GetState() State
	Execute() State
	Cancel()
	Pause()
	Start()
}

type Tasks

type Tasks struct {
	// contains filtered or unexported fields
}

func Instance

func Instance() *Tasks

func NewTasks

func NewTasks(groupNum uint32) *Tasks

func (*Tasks) AddTask

func (job *Tasks) AddTask(task Task)

func (*Tasks) AddTriggerTask

func (job *Tasks) AddTriggerTask(task Task, trigger Trigger) error

func (*Tasks) HasTask

func (job *Tasks) HasTask(jobId string) bool

func (*Tasks) RemoveTask

func (job *Tasks) RemoveTask(jobId string)

func (*Tasks) Run

func (job *Tasks) Run()

func (*Tasks) StopTask

func (job *Tasks) StopTask(jobId string)

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.

Jump to

Keyboard shortcuts

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