schedule

package
v0.1.5 Latest Latest
Warning

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

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

Documentation

Overview

Package schedule 提供资源映射以及任务调度器

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("task schduler closed")
)

已关闭错误

Functions

This section is empty.

Types

type AsyncTask

type AsyncTask interface {
	Do() error   //同步执行
	Post() error //后续通知
}

AsyncTask 异步任务

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) Close

func (a *AsyncTaskScheduler) Close() error

Close 关闭

func (*AsyncTaskScheduler) Errors

func (a *AsyncTaskScheduler) Errors() <-chan error

Errors 错误监听器

func (*AsyncTaskScheduler) Push

func (a *AsyncTaskScheduler) Push(task AsyncTask) (err error)

Push 异步执行任务task

func (*AsyncTaskScheduler) Size

func (a *AsyncTaskScheduler) Size() int32

Size 正在异步任务调度器中的任务

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 幂重试策略

func (*ExponentialStrategy) Next

func (r *ExponentialStrategy) Next(err error, n int) (retry bool, wait time.Duration)

Next 通过错误err,获取下次是否重试retry以及下次时间间隔wait,在幂重试策略最大时间间隔

type ForeverRetryConfig

type ForeverRetryConfig struct {
	Wait time2.Duration `json:"wait"`
}

ForeverRetryConfig 永久重复重试策略

type ForeverRetryStrategy

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

ForeverRetryStrategy 永久重试策略

func (*ForeverRetryStrategy) Next

func (r *ForeverRetryStrategy) Next(err error, _ int) (retry bool, wait time.Duration)

Next 通过错误err,获取下次是否重试retry以及下次时间间隔wait,在永久重试策略没有最大重试次数,当前次数n没有作用

type MappedResource

type MappedResource interface {
	Resource

	Key() string //关键字
}

MappedResource 可映射资源

type MappedTask

type MappedTask interface {
	Key() string //映射主键
}

MappedTask 映射任务

type MappedTaskManager

type MappedTaskManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MappedTaskManager 任务管理器 toto 不知道为什么len(remain) + len(run) 无法实时任务数,其中主要是len(run)不准确

func NewTaskManager

func NewTaskManager() *MappedTaskManager

NewTaskManager 创建任务管理器

func (*MappedTaskManager) IsEmpty

func (t *MappedTaskManager) IsEmpty() bool

IsEmpty 任务管理器是否为空

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 获取当前在跑的任务

func (*MappedTaskManager) Size

func (t *MappedTaskManager) Size() int

Size 任务数,包含待执行和运行任务

type NTimesRetryConfig

type NTimesRetryConfig struct {
	N    int            `json:"n"`
	Wait time2.Duration `json:"wait"`
}

NTimesRetryConfig n次数重复重试策略

type NTimesRetryStrategy

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

NTimesRetryStrategy n次数重复重试策略

func (*NTimesRetryStrategy) Next

func (r *NTimesRetryStrategy) Next(err error, n int) (retry bool, wait time.Duration)

Next 通过错误err以及当前次数n获取下次是否重试retry以及下次时间间隔wait

type NoneRetryStrategy

type NoneRetryStrategy struct{}

NoneRetryStrategy 无重试策略

func (*NoneRetryStrategy) Next

func (r *NoneRetryStrategy) Next(err error, n int) (retry bool, wait time.Duration)

Next 下一次是否retry需要重试,wait等待时间

type Resource

type Resource interface {
	Close() error //关闭释放资源
}

Resource 资源

type ResourceMap

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

ResourceMap 资源映射,每一个资源类似于智能指针

func NewResourceMap

func NewResourceMap() *ResourceMap

NewResourceMap 创建资源映射

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 RetryJudger

type RetryJudger interface {
	ShouldRetry(err error) bool
}

RetryJudger 重试判断器

type RetryStrategy

type RetryStrategy interface {
	Next(err error, n int) (retry bool, wait time.Duration)
}

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 NewNoneRetryStrategy

func NewNoneRetryStrategy() RetryStrategy

NewNoneRetryStrategy 创建无重试策略

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生成重试任务

func (*RetryTask) Do

func (r *RetryTask) Do() (err error)

Do 同步执行

type Task

type Task interface {
	Do() error //同步执行
}

Task 任务

type TaskSchduler

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

TaskSchduler 任务调度器

func NewTaskSchduler

func NewTaskSchduler(workerNumer, cap int) *TaskSchduler

NewTaskSchduler 根据执行者数workerNumer,待执行队列容量cao生成任务调度器

func (*TaskSchduler) Push

func (t *TaskSchduler) Push(task Task) (<-chan error, error)

Push 将任务task加入队列,获得执行结果通知信道,在已关闭时报错

func (*TaskSchduler) Size

func (t *TaskSchduler) Size() int32

Size 待执行队列大小

func (*TaskSchduler) Stop

func (t *TaskSchduler) Stop()

Stop 停止任务调度器

Jump to

Keyboard shortcuts

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