jobs

package
v2.10.18 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJob

func AddJob(delay time.Duration, job JobWorker, options ...ItemOption)

func DelJob added in v2.0.8

func DelJob(id int64)

Types

type ItemOption added in v2.0.8

type ItemOption func(j *JobItem)

func WithItemDebug added in v2.0.8

func WithItemDebug(debug bool) ItemOption

func WithItemId added in v2.0.8

func WithItemId(id int64) ItemOption

func WithItemReplace added in v2.9.5

func WithItemReplace(replace bool) ItemOption

type Job added in v2.0.7

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

func NewJob added in v2.0.7

func NewJob(worker func(), options ...Option) *Job

func (*Job) BeforeExec added in v2.0.7

func (j *Job) BeforeExec()

func (*Job) CanExec added in v2.0.7

func (j *Job) CanExec() bool

func (*Job) FailNext added in v2.0.7

func (j *Job) FailNext() (bool, time.Duration)

func (*Job) JobExec added in v2.0.7

func (j *Job) JobExec() bool

func (*Job) JobFinish added in v2.0.7

func (j *Job) JobFinish()

func (*Job) Name added in v2.0.7

func (j *Job) Name() string

func (*Job) String added in v2.1.1

func (j *Job) String() string

type JobItem

type JobItem struct {
	JobId     int64     //任务标识
	AddTime   int64     //添加时间
	BeginTime int64     //开始时间
	Worker    JobWorker //任务对象
	StartTime int64     //开始时间
	Debug     bool      //是否调试
	Id        string    //任务唯一标识
	Replace   bool      //同jobid是否替换
}

func NewJobItem

func NewJobItem(delay time.Duration, worker JobWorker, options ...ItemOption) *JobItem

func (*JobItem) ExecJob

func (s *JobItem) ExecJob()

func (*JobItem) FinishJob

func (s *JobItem) FinishJob()

type JobKeeper

type JobKeeper struct {
	Name     string
	List     JobQueues
	Index    map[int64]*JobQueue
	AddChan  chan *JobItem
	DelChan  chan int64
	StopChan chan struct{}
	IdList   map[int64]map[int64]int
}

func NewJobKeeper

func NewJobKeeper(name string) *JobKeeper

func (*JobKeeper) AddJob

func (k *JobKeeper) AddJob(delay time.Duration, job JobWorker, options ...ItemOption)

func (*JobKeeper) DelJob added in v2.0.8

func (k *JobKeeper) DelJob(delId int64)

func (*JobKeeper) ExecJob

func (k *JobKeeper) ExecJob()

func (*JobKeeper) Stop added in v2.5.5

func (k *JobKeeper) Stop()

type JobQueue

type JobQueue struct {
	StartTime int64     //开始时间
	JobItems  *ds.Queue //任务队列
	// contains filtered or unexported fields
}

func NewJobQueue

func NewJobQueue(sTime int64) *JobQueue

func (*JobQueue) AddJob

func (s *JobQueue) AddJob(job *JobItem)

func (*JobQueue) DelJob added in v2.0.8

func (s *JobQueue) DelJob(delId int64)

func (*JobQueue) ExeJob

func (s *JobQueue) ExeJob()

type JobQueues

type JobQueues []*JobQueue

func (JobQueues) Len

func (q JobQueues) Len() int

func (JobQueues) Less

func (q JobQueues) Less(i, j int) bool

func (JobQueues) Swap

func (q JobQueues) Swap(i, j int)

type JobWorker

type JobWorker interface {
	String() string                  //任务名称
	BeforeExec()                     //任务执行前操作
	CanExec() bool                   //是否可以执行
	JobExec() bool                   //执行任务,返回执行是否完成
	FailNext() (bool, time.Duration) //失败是否继续执行并且延缓执行时间
	JobFinish()                      //任务执行完成触发
}

type Option added in v2.0.7

type Option func(j *Job)

func WithInterval added in v2.0.7

func WithInterval(interval time.Duration) Option

func WithName added in v2.0.8

func WithName(name string) Option

func WithRepeat added in v2.0.7

func WithRepeat(repeat int) Option

Jump to

Keyboard shortcuts

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