Documentation
¶
Index ¶
- Variables
- type Callback
- type Config
- type EmptyCallback
- type ParentRef
- type Scheduler
- func (s *Scheduler) Delete(id string)
- func (s *Scheduler) Get(id string) *Task
- func (s *Scheduler) GetTaskCount() int
- func (s *Scheduler) Set(name string, handleFunc TaskHandleFunc, delay time.Duration) string
- func (s *Scheduler) SetAt(name string, handleFunc TaskHandleFunc, execAt time.Time) string
- func (s *Scheduler) Stop()
- type Task
- type TaskHandleFunc
- type TaskMetadata
- type TaskRef
- type WaitForContextDone
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorTaskCanceled 表示任务被取消 // ErrorTaskCanceled represents the task is canceled ErrorTaskCanceled = errors.New("task canceled") // ErrorTaskTimeout 表示任务超时 // ErrorTaskTimeout represents the task is timeout ErrorTaskTimeout = errors.New("task timeout") // ErrorTaskEarlyReturn 表示任务提前返回 // ErrorTaskEarlyReturn represents the task returns early ErrorTaskEarlyReturn = errors.New("task early return") )
定义一些常见的任务错误 Define some common task errors
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback interface { // OnTaskAdded 是当任务被添加时的回调函数,它接收任务 id、任务名称和执行时间作为参数 // OnTaskAdded is the callback function when a task is added, it takes the task id, task name, and execution time as parameters OnTaskAdded(id, name string, execAt time.Time) // OnTaskExecuted 是当任务被执行时的回调函数,它接收任务 id、任务名称、数据、原因和错误作为参数 // OnTaskExecuted is the callback function when a task is executed, it takes the task id, task name, data, reason, and error as parameters OnTaskExecuted(id, name string, data interface{}, reason, err error) // OnTaskRemoved 是当任务被移除时的回调函数,它接收任务 id 和任务名称作为参数 // OnTaskRemoved is the callback function when a task is removed, it takes the task id and task name as parameters OnTaskRemoved(id, name string) }
Callback 是一个接口,定义了任务添加、执行和移除时的回调函数 Callback is an interface that defines the callback functions when a task is added, executed, and removed
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config 是一个结构体,包含一个 Callback 类型的字段 Config is a struct that contains a field of type Callback
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig 是一个函数,用于获取默认的 Config 实例 DefaultConfig is a function used to get the default instance of Config
func NewConfig ¶
func NewConfig() *Config
NewConfig 是一个函数,用于创建一个新的 Config 实例 NewConfig is a function used to create a new instance of Config
func (*Config) WithCallback ¶
WithCallback 是 Config 的一个方法,用于设置 Config 的 callback 字段 WithCallback is a method of Config, used to set the callback field of Config
type EmptyCallback ¶
type EmptyCallback struct{}
EmptyCallback 是一个空的回调实现,它的所有方法都是空操作 EmptyCallback is an empty callback implementation, all of its methods are no-ops
func NewEmptyTaskCallback ¶
func NewEmptyTaskCallback() *EmptyCallback
NewEmptyTaskCallback 是一个函数,它返回一个新的 EmptyCallback 实例 NewEmptyTaskCallback is a function that returns a new instance of EmptyCallback
func (EmptyCallback) OnTaskAdded ¶
func (EmptyCallback) OnTaskAdded(id, name string, execAt time.Time)
OnTaskAdded 是 EmptyCallback 的一个方法,它是一个空操作 OnTaskAdded is a method of EmptyCallback, it is a no-op
func (EmptyCallback) OnTaskExecuted ¶
func (EmptyCallback) OnTaskExecuted(id, name string, data interface{}, reason, err error)
OnTaskExecuted 是 EmptyCallback 的一个方法,它是一个空操作 OnTaskExecuted is a method of EmptyCallback, it is a no-op
func (EmptyCallback) OnTaskRemoved ¶
func (EmptyCallback) OnTaskRemoved(id, name string)
OnTaskRemoved 是 EmptyCallback 的一个方法,它是一个空操作 OnTaskRemoved is a method of EmptyCallback, it is a no-op
type ParentRef ¶
type ParentRef struct {
// contains filtered or unexported fields
}
ParentRef 结构体包含一个上下文和一个取消函数。 The ParentRef struct contains a context and a cancel function.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler 结构体定义了一个调度器,它包含了一些用于任务调度的关键字段。 The Scheduler struct defines a scheduler, which contains some key fields for task scheduling.
func New ¶
New 是一个函数,接收一个指向 Config 结构体的指针作为参数,返回一个新的 Scheduler 结构体指针。 New is a function that takes a pointer to a Config struct as a parameter and returns a new pointer to a Scheduler struct.
func (*Scheduler) Delete ¶
Delete 是一个方法,用于删除指定 ID 的任务。 Delete is a method used to delete the task with the specified ID.
func (*Scheduler) Get ¶
Get 是一个方法,用于获取指定 ID 的任务。 Get is a method used to get the task with the specified ID.
func (*Scheduler) GetTaskCount ¶
GetTaskCount 是一个方法,用于获取调度器中的任务数量。 GetTaskCount is a method used to get the number of tasks in the scheduler.
func (*Scheduler) Set ¶
Set 是一个方法,用于在指定的延迟后执行任务。 Set is a method used to execute tasks after a specified delay.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task 结构体定义 Definition of Task struct
func NewTask ¶
func NewTask(parentCtx context.Context, name string, handleFunc TaskHandleFunc) *Task
NewTask 函数用于创建一个新的任务 The NewTask function is used to create a new task
func (*Task) Cancel ¶
func (t *Task) Cancel()
Cancel 方法用于取消任务 The Cancel method is used to cancel the task
func (*Task) EarlyReturn ¶
func (t *Task) EarlyReturn()
EarlyReturn 方法用于提前返回任务 The EarlyReturn method is used to return the task early
func (*Task) GetMetadata ¶
func (t *Task) GetMetadata() *TaskMetadata
GetMetadata 方法用于获取任务的元数据 The GetMetadata method is used to get the metadata of the task
type TaskHandleFunc ¶
type TaskHandleFunc = func(done WaitForContextDone) (data interface{}, err error)
TaskHandleFunc 是一个函数类型,它接收一个 WaitForContextDone 参数,并返回一个接口类型的数据和一个错误 TaskHandleFunc is a function type that takes a WaitForContextDone parameter and returns an interface type data and an error
var DefaultTaskHandleFunc TaskHandleFunc = func(done WaitForContextDone) (data any, err error) { return nil, nil }
DefaultTaskHandleFunc 是默认的任务处理函数,它返回 nil 数据和 nil 错误 DefaultTaskHandleFunc is the default task handling function, it returns nil data and nil error
type TaskMetadata ¶
type TaskMetadata struct {
// contains filtered or unexported fields
}
TaskMetadata 结构体包含任务的 id、name 和 handleFunc The TaskMetadata struct contains the id, name and handleFunc of the task
func (*TaskMetadata) GetHandleFunc ¶
func (stm *TaskMetadata) GetHandleFunc() TaskHandleFunc
GetHandleFunc 方法返回任务的 handleFunc The GetHandleFunc method returns the handleFunc of the task
func (*TaskMetadata) GetID ¶
func (stm *TaskMetadata) GetID() string
GetID 方法返回任务的 id The GetID method returns the id of the task
func (*TaskMetadata) GetName ¶
func (stm *TaskMetadata) GetName() string
GetName 方法返回任务的 name The GetName method returns the name of the task
type TaskRef ¶
type TaskRef struct {
// contains filtered or unexported fields
}
TaskRef 结构体包含一个父引用和一个任务。 The TaskRef struct contains a parent reference and a task.
type WaitForContextDone ¶
type WaitForContextDone = <-chan struct{}
WaitForContextDone 是一个只能接收的通道,用于等待上下文完成 WaitForContextDone is a receive-only channel used to wait for context completion