async_task_manager

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: LGPL-2.1 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagerInit   uint8 = 0
	ManagerStart  uint8 = 1
	ManagerStop   uint8 = 2
	ManagerFinish uint8 = 3
	ManagerError  uint8 = 4
)
View Source
const (
	TaskONInit   uint8 = 0
	TaskONStart  uint8 = 1
	TaskONStop   uint8 = 2
	TaskONFinish uint8 = 3
	TaskONError  uint8 = 4
)
View Source
const (
	DefaultWaitLength int = 1000
	DefaultWorkLength int = 100
)
View Source
const TaskSep = "##ASYNCTASK%%"

Variables

View Source
var UserStopError error

Functions

func GetUUID

func GetUUID() string

GetUUID 生成一个UUID,全局唯一值

Types

type AsyncTaskCallBack

type AsyncTaskCallBack func(AsyncTaskInterface)

AsyncTaskCallBack 异步任务回调

type AsyncTaskHandle

type AsyncTaskHandle interface {
	Start(AsyncTaskInterface)              // 开始执行任务
	Stop()                                 // 结束任务,然后拉起回调,返回enmu.UserStopError
	SetHandleCallBack(f AsyncTaskCallBack) // 配置执行的回调
}

type AsyncTaskInterface

type AsyncTaskInterface interface {
	GetTag() *TaskTag       // 任务全局唯一标识
	SetStartUnix(end int64) // 设置任务开始时间
	GetStartUnix() int64    // 获取任务开始时间
	SetEndUnix(end int64)   // 设置任务结束时间
	GetEndUnix() int64      // 获取任务结束时间
	SetStatus(s uint8)      // 设置当前任务状态
	GetStatus() uint8       // 获取当前任务状态
	SetError(e error)
	GetError() error
}

type AsyncTaskManagerInterface

type AsyncTaskManagerInterface interface {
	Start()                                                                              // 开始
	Stop()                                                                               // 停止
	SetWaitListMaxLength(l int)                                                          // 设置等待队列的最大长度,默认:1000
	SetWorkPoolSize(s int)                                                               // 设置并行的数量,默认:100
	AddAsyncTask(t AsyncTaskInterface, h AsyncTaskHandle, cb ...AsyncTaskCallBack) error // 增加一个异步任务
	SetFinishCallBack(f func(*TaskManagerResult))                                        // 设置任务完成的回调,定长任务有效
	CheckTaskInWork(tag string) (bool, error)                                            // 查验任务是否在执行
	GetWaitLength() int                                                                  // 获取当前等待队列长度
	GetWorkerLength() int                                                                // 获取当前工作队列长度
	GetManagerStatus() uint8                                                             // 获取管理器状态
	SetTaskMaxLength(s int)                                                              // 设置最大任务数
	SetProgressCallBack(p int, cb ProgressCallBack)                                      // 设置进度回调,定长任务有效
}

AsyncTaskManagerInterface 异步任务管理器通用接口,几个Set方法尽量保证在Start()之前有效

type DefaultAsyncTask

type DefaultAsyncTask struct {
	Tag    *TaskTag
	Start  int64
	End    int64
	Status uint8
	Err    error
}

func (*DefaultAsyncTask) GetEndUnix

func (t *DefaultAsyncTask) GetEndUnix() int64

func (*DefaultAsyncTask) GetError

func (t *DefaultAsyncTask) GetError() error

func (*DefaultAsyncTask) GetStartUnix

func (t *DefaultAsyncTask) GetStartUnix() int64

func (*DefaultAsyncTask) GetStatus

func (t *DefaultAsyncTask) GetStatus() uint8

func (*DefaultAsyncTask) GetTag

func (t *DefaultAsyncTask) GetTag() *TaskTag

func (*DefaultAsyncTask) SetEndUnix

func (t *DefaultAsyncTask) SetEndUnix(end int64)

func (*DefaultAsyncTask) SetError

func (t *DefaultAsyncTask) SetError(e error)

func (*DefaultAsyncTask) SetStartUnix

func (t *DefaultAsyncTask) SetStartUnix(start int64)

func (*DefaultAsyncTask) SetStatus

func (t *DefaultAsyncTask) SetStatus(s uint8)

type DefaultAsyncTaskManager

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

func NewDefaultAsyncTaskManager

func NewDefaultAsyncTaskManager() *DefaultAsyncTaskManager

func (*DefaultAsyncTaskManager) AddAsyncTask

func (*DefaultAsyncTaskManager) CheckTaskInWork

func (m *DefaultAsyncTaskManager) CheckTaskInWork(workTag string) (bool, error)

func (*DefaultAsyncTaskManager) GetManagerStatus

func (m *DefaultAsyncTaskManager) GetManagerStatus() uint8

func (*DefaultAsyncTaskManager) GetWaitLength

func (m *DefaultAsyncTaskManager) GetWaitLength() int

func (*DefaultAsyncTaskManager) GetWorkerLength

func (m *DefaultAsyncTaskManager) GetWorkerLength() int

func (*DefaultAsyncTaskManager) SetFinishCallBack

func (m *DefaultAsyncTaskManager) SetFinishCallBack(f func(*TaskManagerResult))

func (*DefaultAsyncTaskManager) SetProgressCallBack

func (m *DefaultAsyncTaskManager) SetProgressCallBack(p int, cb ProgressCallBack)

func (*DefaultAsyncTaskManager) SetTaskMaxLength

func (m *DefaultAsyncTaskManager) SetTaskMaxLength(s int)

func (*DefaultAsyncTaskManager) SetWaitListMaxLength

func (m *DefaultAsyncTaskManager) SetWaitListMaxLength(l int)

func (*DefaultAsyncTaskManager) SetWorkPoolSize

func (m *DefaultAsyncTaskManager) SetWorkPoolSize(s int)

func (*DefaultAsyncTaskManager) Start

func (m *DefaultAsyncTaskManager) Start()

func (*DefaultAsyncTaskManager) Stop

func (m *DefaultAsyncTaskManager) Stop()

func (*DefaultAsyncTaskManager) TaskResultCallBack

func (m *DefaultAsyncTaskManager) TaskResultCallBack(res AsyncTaskInterface)

type DefaultOneToManyTask added in v1.0.0

type DefaultOneToManyTask struct {
	*DefaultAsyncTask
	// contains filtered or unexported fields
}

func NewDefaultOneToManyTask added in v1.0.0

func NewDefaultOneToManyTask(taskTarget string) *DefaultOneToManyTask

func (*DefaultOneToManyTask) Copy added in v1.0.0

func (*DefaultOneToManyTask) GetHandleResult added in v1.0.0

func (t *DefaultOneToManyTask) GetHandleResult() interface{}

func (*DefaultOneToManyTask) GetHandleTag added in v1.0.0

func (t *DefaultOneToManyTask) GetHandleTag() *TaskTag

func (*DefaultOneToManyTask) SetHandleResult added in v1.0.0

func (t *DefaultOneToManyTask) SetHandleResult(res interface{})

func (*DefaultOneToManyTask) SetHandleTag added in v1.0.0

func (t *DefaultOneToManyTask) SetHandleTag(tag *TaskTag)

func (*DefaultOneToManyTask) SetTaskTag added in v1.0.0

func (t *DefaultOneToManyTask) SetTaskTag(tag *TaskTag)

type DefaultOneToManyTaskManager added in v1.0.0

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

func (*DefaultOneToManyTaskManager) AddAsyncTask added in v1.0.0

func (*DefaultOneToManyTaskManager) CheckTaskInWork added in v1.0.0

func (m *DefaultOneToManyTaskManager) CheckTaskInWork(workTag string) (bool, error)

func (*DefaultOneToManyTaskManager) FinishTouch added in v1.0.0

func (m *DefaultOneToManyTaskManager) FinishTouch()

FinishTouch 任务完成后触发从等待队列加入到工作队列

func (*DefaultOneToManyTaskManager) GetManagerStatus added in v1.0.0

func (m *DefaultOneToManyTaskManager) GetManagerStatus() uint8

func (*DefaultOneToManyTaskManager) GetWaitLength added in v1.0.0

func (m *DefaultOneToManyTaskManager) GetWaitLength() int

func (*DefaultOneToManyTaskManager) GetWorkerLength added in v1.0.0

func (m *DefaultOneToManyTaskManager) GetWorkerLength() int

func (*DefaultOneToManyTaskManager) SetWaitListMaxLength added in v1.0.0

func (m *DefaultOneToManyTaskManager) SetWaitListMaxLength(l int)

func (*DefaultOneToManyTaskManager) SetWorkPoolSize added in v1.0.0

func (m *DefaultOneToManyTaskManager) SetWorkPoolSize(s int)

func (*DefaultOneToManyTaskManager) Start added in v1.0.0

func (m *DefaultOneToManyTaskManager) Start()

func (*DefaultOneToManyTaskManager) Stop added in v1.0.0

func (m *DefaultOneToManyTaskManager) Stop()

type OneToManyTaskHandleInterface added in v1.0.0

type OneToManyTaskHandleInterface interface {
	Start(AsyncTaskInterface)              // 开始执行任务
	Stop()                                 // 结束任务,然后拉起回调,返回enmu.UserStopError
	SetHandleCallBack(f AsyncTaskCallBack) // 配置执行的回调
	GetTarget() *TaskTag                   // 同一任务中唯一
}

OneToManyTaskHandleInterface 一对多异步任务Handle通用接口

type OneToManyTaskInterface added in v1.0.0

type OneToManyTaskInterface interface {
	AsyncTaskInterface
	SetTaskTag(tag *TaskTag)
	GetHandleTag() *TaskTag
	SetHandleTag(tag *TaskTag)
	GetHandleResult() interface{}
	SetHandleResult(res interface{})
	Copy() OneToManyTaskInterface
}

OneToManyTaskInterface 一对多异步任务通用接口

type OneToManyTaskManagerInterface added in v1.0.0

type OneToManyTaskManagerInterface interface {
	Start()                                                                                                                  // 开始
	Stop()                                                                                                                   // 停止
	SetWaitListMaxLength(l int)                                                                                              // 设置等待队列的最大长度,默认:1000
	SetWorkPoolSize(s int)                                                                                                   // 设置并行的数量,默认:100
	AddAsyncTask(t OneToManyTaskInterface, cb func(res *OneToManyTaskResult), handles ...OneToManyTaskHandleInterface) error // 增加一个异步任务
	CheckTaskInWork(tag string) (bool, error)                                                                                // 查验任务是否在执行
	GetWaitLength() int                                                                                                      // 获取当前等待队列长度
	GetWorkerLength() int                                                                                                    // 获取当前工作队列长度
	GetManagerStatus() uint8                                                                                                 // 获取管理器状态
}

OneToManyTaskManagerInterface 一对多异步任务管理通用接口

type OneToManyTaskResult added in v1.0.0

type OneToManyTaskResult struct {
	StartTime int64
	EndTime   int64
	Status    uint8
	Task      OneToManyTaskInterface
	ResultMap map[string]interface{}
}

OneToManyTaskResult 一对多异步任务 执行结果

type ProgressCallBack

type ProgressCallBack func(*TaskProgress)

ProgressCallBack 进度回调

type TaskManagerResult

type TaskManagerResult struct {
	StartTime int64
	EndTime   int64
	Length    uint64
	TagsMap   map[string]AsyncTaskInterface
	Status    uint8
}

TaskManagerResult 任务管理器执行结果

type TaskProgress

type TaskProgress struct {
	WorkNum    int   // 任务并行数
	AllTaskNum int   // 总任务数,如果没有SetTaskMaxLength(),返回0
	Progress   int   // 当前完成个数
	ParentTime int64 // 上次进度回调的时间
}

TaskProgress 进度信息

type TaskTag

type TaskTag struct {
	Id   string
	Mark string
}

func NewTaskTag

func NewTaskTag(tag string) *TaskTag

func (*TaskTag) Parse

func (t *TaskTag) Parse(s string) (err error)

func (*TaskTag) String

func (t *TaskTag) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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