async_task

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IReport

type IReport interface {
	// Phase 上报运行阶段,bool表示finished/failed是否删除任务记录
	Phase() (RunPhase, bool)
	// Context 上报上下文
	Context() string
}

IReport 任务上报interface,注意goroutine safe

type ITask

type ITask interface {
	// Running 任务执行,任务接收到stop消息后,须主动Report,之后退出即可
	Running(ctx context.Context, taskCtx string, stop <-chan struct{}) <-chan IReport
	// Deleting 删除任务
	Deleting(ctx context.Context, taskCtx string, stop <-chan struct{}) <-chan IReport
}

ITask 异步任务interface

type ITaskFunc

type ITaskFunc func() ITask

ITaskFunc 异步任务初始化方法

type RunPhase

type RunPhase int32

RunPhase 任务运行阶段

const (
	RunPhaseFailed   RunPhase = -1 // 失败
	RunPhaseNormal   RunPhase = 1  // 正常
	RunPhaseFinished RunPhase = 2  // 完成
)

type State

type State int32

State 任务状态

const (
	StateInit      State = 0 // 已创建
	StatePending   State = 1 // 排队中
	StateRunning   State = 2 // 运行中
	StateCanceling State = 3 // 取消中
	StatePause     State = 4 // 暂停
	StateFinished  State = 5 // 结束
	StateFailed    State = 6 // 失败
)

type Task

type Task struct {
	ID        uint32
	User      string
	Group     string
	Type      uint32
	State     State
	CreatedAt int64
	DoneAt    int64
	Ctx       string
}

Jump to

Keyboard shortcuts

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