Documentation ¶
Overview ¶
Package schedule 提供资源映射以及任务调度器
Index ¶
- Variables
- type AsyncTask
- type AsyncTaskScheduler
- type ExponentialRetryConfig
- type ExponentialStrategy
- type ForeverRetryConfig
- type ForeverRetryStrategy
- type MappedResource
- type MappedTask
- type MappedTaskManager
- func (t *MappedTaskManager) IsEmpty() bool
- func (t *MappedTaskManager) PopRemainAndAddRun() (task MappedTask, ok bool)
- func (t *MappedTaskManager) PushRemain(task MappedTask)
- func (t *MappedTaskManager) RemoveRun(task MappedTask)
- func (t *MappedTaskManager) RemoveRunAndPushRemain(task MappedTask)
- func (t *MappedTaskManager) Runs() (tasks []MappedTask)
- func (t *MappedTaskManager) Size() int
- type NTimesRetryConfig
- type NTimesRetryStrategy
- type NoneRetryStrategy
- type Resource
- type ResourceMap
- type RetryJudger
- type RetryStrategy
- func NewExponentialRetryStrategy(j RetryJudger, init, max time.Duration) RetryStrategy
- func NewForeverRetryStrategy(j RetryJudger, wait time.Duration) RetryStrategy
- func NewNTimesRetryStrategy(j RetryJudger, n int, wait time.Duration) RetryStrategy
- func NewNoneRetryStrategy() RetryStrategy
- func NewRetryStrategy(j RetryJudger, conf *config.JSON) (s RetryStrategy, err error)
- type RetryTask
- type Task
- type TaskSchduler
Constants ¶
This section is empty.
Variables ¶
var (
ErrClosed = errors.New("task schduler closed")
)
已关闭错误
Functions ¶
This section is empty.
Types ¶
type AsyncTaskScheduler ¶
type AsyncTaskScheduler struct {
// contains filtered or unexported fields
}
AsyncTaskScheduler 异步任务调度器
func NewAsyncTaskScheduler ¶
func NewAsyncTaskScheduler(ctx context.Context, numWorker, chanSize int) *AsyncTaskScheduler
NewAsyncTaskScheduler 通过上下文ctx, 并行任务数numWorker, 任务数大小chanSize创建异步任务调度器
func (*AsyncTaskScheduler) Push ¶
func (a *AsyncTaskScheduler) Push(task AsyncTask) (err error)
Push 异步执行任务task
type ExponentialRetryConfig ¶
type ExponentialRetryConfig struct { Init time2.Duration `json:"init"` Max time2.Duration `json:"max"` }
ExponentialRetryConfig 幂重复重试策略
type ExponentialStrategy ¶
type ExponentialStrategy struct {
// contains filtered or unexported fields
}
ExponentialStrategy 幂重试策略
type ForeverRetryConfig ¶
ForeverRetryConfig 永久重复重试策略
type ForeverRetryStrategy ¶
type ForeverRetryStrategy struct {
// contains filtered or unexported fields
}
ForeverRetryStrategy 永久重试策略
type MappedResource ¶
MappedResource 可映射资源
type MappedTaskManager ¶
MappedTaskManager 任务管理器 toto 不知道为什么len(remain) + len(run) 无法实时任务数,其中主要是len(run)不准确
func (*MappedTaskManager) PopRemainAndAddRun ¶
func (t *MappedTaskManager) PopRemainAndAddRun() (task MappedTask, ok bool)
PopRemainAndAddRun 从待执行队列移到运行队列中
func (*MappedTaskManager) PushRemain ¶
func (t *MappedTaskManager) PushRemain(task MappedTask)
PushRemain 把任务加入待执行队列
func (*MappedTaskManager) RemoveRun ¶
func (t *MappedTaskManager) RemoveRun(task MappedTask)
RemoveRun 从运行队列移除出任务
func (*MappedTaskManager) RemoveRunAndPushRemain ¶
func (t *MappedTaskManager) RemoveRunAndPushRemain(task MappedTask)
RemoveRunAndPushRemain 从运行队列移动到待执行队列
func (*MappedTaskManager) Runs ¶ added in v0.1.2
func (t *MappedTaskManager) Runs() (tasks []MappedTask)
Runs 获取当前在跑的任务
type NTimesRetryConfig ¶
NTimesRetryConfig n次数重复重试策略
type NTimesRetryStrategy ¶
type NTimesRetryStrategy struct {
// contains filtered or unexported fields
}
NTimesRetryStrategy n次数重复重试策略
type ResourceMap ¶
type ResourceMap struct {
// contains filtered or unexported fields
}
ResourceMap 资源映射,每一个资源类似于智能指针
func (*ResourceMap) Get ¶
func (r *ResourceMap) Get(key string, create func() (MappedResource, error)) (resource MappedResource, err error)
Get 根据关键字key获取资源,若不存在,就通过函数create创建资源 若创建资源错误时,就会返回错误
func (*ResourceMap) Release ¶
func (r *ResourceMap) Release(resource MappedResource) (err error)
Release 根据资源resource释放资源,若不存在,就通过函数create创建资源 若创建资源错误时,就会返回错误
func (*ResourceMap) UseCount ¶
func (r *ResourceMap) UseCount(resource MappedResource) int
UseCount 根据资源resource计算已使用个数
type RetryStrategy ¶
RetryStrategy 重试策略
func NewExponentialRetryStrategy ¶
func NewExponentialRetryStrategy(j RetryJudger, init, max time.Duration) RetryStrategy
NewExponentialRetryStrategy 通过重试判定器j,开始时间间隔init以及最大时间间隔max创建幂重试策略
func NewForeverRetryStrategy ¶
func NewForeverRetryStrategy(j RetryJudger, wait time.Duration) RetryStrategy
NewForeverRetryStrategy 通过重试判定器j以及重试间隔wait创建永久重试策略
func NewNTimesRetryStrategy ¶
func NewNTimesRetryStrategy(j RetryJudger, n int, wait time.Duration) RetryStrategy
NewNTimesRetryStrategy 通过重试判定器j,最大次数n以及重试间隔wait创建n次数重复重试策略
func NewRetryStrategy ¶
func NewRetryStrategy(j RetryJudger, conf *config.JSON) (s RetryStrategy, err error)
NewRetryStrategy 根据配置文件生成重试策略
type RetryTask ¶
type RetryTask struct {
// contains filtered or unexported fields
}
RetryTask 重试任务
func NewRetryTask ¶
func NewRetryTask(ctx context.Context, strategy RetryStrategy, task Task) *RetryTask
NewRetryTask 通过上下文关系ctx,重试策略strategy以及任务task生成重试任务
type TaskSchduler ¶
type TaskSchduler struct {
// contains filtered or unexported fields
}
TaskSchduler 任务调度器
func NewTaskSchduler ¶
func NewTaskSchduler(workerNumer, cap int) *TaskSchduler
NewTaskSchduler 根据执行者数workerNumer,待执行队列容量cao生成任务调度器