task

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IJob added in v0.0.4

type IJob interface {
	IRunJob
	IStopJob
}

IJobe 实现此接口用于执行指定作业任务

type IRunJob added in v0.0.4

type IRunJob interface {
	RunJob() error
}

type IStopJob added in v0.0.4

type IStopJob interface {
	StopJob()
}

type Job

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

Job 作业任务

func NewJob

func NewJob(job IJob) *Job

NewJob 新建一个作业 列如:

var JobFunc1 JobFunc = func() errs {
		fmt.Println("第一个任务,我运行了")
		return nil
	}

job1 := NewJob(jobFun1)

func (*Job) IsRun

func (j *Job) IsRun() bool

IsRun 作业任务状态

func (*Job) JobId

func (j *Job) JobId() string

JobId 作业任务ID

func (*Job) Run

func (j *Job) Run() error

Run 执行作业,至到调用 Stop 关闭

func (*Job) RunWithDeadline

func (j *Job) RunWithDeadline(d time.Time) error

RunWithDeadline 执行作业任务,超过某个时间点自动停止.

func (*Job) RunWithTimeout

func (j *Job) RunWithTimeout(duration time.Duration) error

RunWithTimeout 执行作业任务,超时自动停止.可调用 Stop 手动关闭.

func (*Job) Stop

func (j *Job) Stop()

Stop 停止作业任务

type JobFunc

type JobFunc func() error

JobFunc 函数式编程实现 IJobe 接口

func (JobFunc) RunJob

func (j JobFunc) RunJob() error

RunJob 实现 IJobe 接口,执行 JobFunc 函数

func (JobFunc) StopJob added in v0.0.4

func (j JobFunc) StopJob()

StopJob 实现 IJobe 接口,执行 JobFunc 函数

type Task

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

Task 任务池

func NewTask

func NewTask() *Task

NewTask 新建一个作业任务池

func (*Task) Add

func (t *Task) Add(job *Job) (jobId string)

Add 添加一个作业任务

func (*Task) Delete

func (t *Task) Delete(id string)

Delete 删除作业任务

func (*Task) Get

func (t *Task) Get(jobId string) *Job

Get 获取作业任务

func (*Task) Run

func (t *Task) Run(jobId string) error

Run 运行一个作业任务

func (*Task) RunWithDeadline

func (t *Task) RunWithDeadline(jobId string, d time.Time) error

RunWithDeadline 执行作业任务,超过某个时间点自动停止

func (*Task) RunWithTimeout

func (t *Task) RunWithTimeout(jobId string, duration time.Duration) error

RunWithTimeout 执行作业任务,超时自动停止

func (*Task) Stop

func (t *Task) Stop(jobId string)

Stop 停止作业任务

Jump to

Keyboard shortcuts

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