scheduler

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 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

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 Job

type Job struct {
	JType    string
	JId      string
	JState   State
	JStartAt int64
	JTimeout time.Duration
	JFunc    JobFunc
	JData    interface{} //自定认数据
}

func BuildJob added in v1.0.59

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

func NewEmptyJob added in v1.4.0

func NewEmptyJob(fn JobFunc) *Job

func NewJob

func NewJob(jType, jobId string, timeout time.Duration) *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) GetKey

func (job *Job) GetKey() string

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

func (job *Job) Start()

func (*Job) WithData added in v1.2.5

func (job *Job) WithData(data interface{}) *Job

func (*Job) WithFunc added in v1.4.0

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

func (*Job) WithTimeOut

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

type JobFunc

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

type JobResult

type JobResult struct {
	JType string      `json:"type"`
	JId   string      `json:"id"`
	Err   error       `json:"err,omitempty"`
	Data  interface{} `json:"data,omitempty"`
}

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) WithResultFunc added in v1.3.59

func (p *Pool) WithResultFunc(fn ResultCallFunc) *Pool

func (*Pool) WithStateFunc added in v1.3.59

func (p *Pool) WithStateFunc(fn StateCallFunc) *Pool

type ResultCallFunc added in v1.3.59

type ResultCallFunc func(state *JobResult)

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 ShellJob

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

func NewShellJob

func NewShellJob(cmd string) *ShellJob

func (*ShellJob) Execute

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

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 StateCallFunc added in v1.2.5

type StateCallFunc func(state int)

0:done, 1:working, -1:release

type Task

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

type Tasks

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

func Instance

func Instance() *Tasks

func NewCapacityTasks added in v1.3.58

func NewCapacityTasks(groupNum uint32, capacity int) *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 {
	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