task

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 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 Executor

type Executor interface {
	Before(param *ExecutorParam) (err error)  // 每次执行之前调用
	Execute(param *ExecutorParam) (err error) // 执行
	After(param *ExecutorParam) (err error)   // 每次执行之后调用
}

type ExecutorParam

type ExecutorParam struct {
	Index       int         `json:"index"`       // 索引号 从 0 开始
	WorkerIndex int         `json:"workerIndex"` // 执行线程编号
	Extend      interface{} `json:"extend"`      // 扩展 业务自己数据可以放在此处

	StartTime time.Time `json:"startTime"`
	EndTime   time.Time `json:"endTime"`

	BeforeStartTime time.Time `json:"beforeStartTime"`
	BeforeEndTime   time.Time `json:"beforeEndTime"`

	ExecuteStartTime time.Time `json:"executeStartTime"`
	ExecuteEndTime   time.Time `json:"executeEndTime"`

	AfterStartTime time.Time `json:"afterStartTime"`
	AfterEndTime   time.Time `json:"afterEndTime"`

	Error error `json:"error"`
	// contains filtered or unexported fields
}

func (*ExecutorParam) IsStopped

func (this_ *ExecutorParam) IsStopped() bool

func (*ExecutorParam) Stop

func (this_ *ExecutorParam) Stop()

type Options

type Options struct {
	Key string `json:"key"` // Key 任务Key,同时只能存在一个

	Worker   int `json:"worker"`   // 任务 并发数
	Duration int `json:"duration"` // 任务 执行持续时长  分钟

	Frequency int `json:"frequency"` // 任务 执行次数,和 时长 互斥,只能一个生效,优先级高于 时长

	Executor Executor `json:"-"`
	// contains filtered or unexported fields
}

type Task

type Task struct {
	*Options

	StartTime time.Time `json:"startTime"`
	EndTime   time.Time `json:"endTime"`
	Errors    []error   `json:"errors"`

	OnStart   func()                     `json:"-"` // DoStart 执行开始
	OnEnd     func()                     `json:"-"` // DoEnd 执行结束
	OnStop    func()                     `json:"-"`
	OnExecute func(param *ExecutorParam) `json:"-"`

	IsStart bool `json:"isStart"` // IsStart 是否启动
	IsEnd   bool `json:"isEnd"`   // IsEnd 是否结束

	ExecutorBeforeCount  int `json:"executorBeforeCount"`
	ExecutorExecuteCount int `json:"executorExecuteCount"`
	ExecutorAfterCount   int `json:"executorAfterCount"`
	ExecutorSuccessCount int `json:"executorSuccessCount"`
	ExecutorErrorCount   int `json:"executorErrorCount"`

	Extend interface{} `json:"extend"`

	Metric *metric.Metric `json:"-"`
	// contains filtered or unexported fields
}

func New

func New(options *Options) (task *Task, err error)

func (*Task) GetNextIndex added in v0.9.4

func (this_ *Task) GetNextIndex() (index int)

func (*Task) IsStopped

func (this_ *Task) IsStopped() bool

func (*Task) Run

func (this_ *Task) Run()

func (*Task) Stop

func (this_ *Task) Stop()

type Worker

type Worker struct {
	*Task
	WorkerIndex int `json:"workerIndex"` // 执行线程编号
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(workerIndex int, task *Task) (worker *Worker)

Jump to

Keyboard shortcuts

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