gtaskqueue

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PriorityCount int = 5
)

Variables

View Source
var (
	ErrorExecTimeout error = errors.Errorf("Exec timeout")
)

Functions

This section is empty.

Types

type Priority

type Priority int
const (
	PriorityHighest Priority = iota + 0
	PriorityHigh
	PriorityMedium
	PriorityLow
	PriorityLowest
)

type Statistic

type Statistic struct {
	// 此刻排队任务个数
	Now2doSize int64
	// 此刻正在执行的任务个数
	NowExecSize int64

	// 近期的开始时间
	LatelyStatisticBeginTime time.Time
	// 近期任务成功次数
	LatelySuccessSize int64
	// 近期等待执行超时次数
	//LatelyWaitTimeoutSize int64
	// 近期执行超时次数
	LatelyExecTimeoutSize int64
	// 近期执行出错次数
	LatelyExecErrorSize int64
	// 近期执行平均耗时
	LatelyAvgExecDuration time.Duration
}

type Task

type Task struct {
	Id            string
	PriorityValue Priority
	ExecTimeout   time.Duration
	DataPtr       interface{}

	// Statistics.
	CreateTime    time.Time
	ExecBeginTime time.Time
	ExecDoneTime  time.Time
	LastError     error
}

type TaskQueue

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

func New

func New(autoResetStatistic time.Duration, size int) *TaskQueue

func (*TaskQueue) Close

func (q *TaskQueue) Close()

Reset taskQueue.

func (*TaskQueue) GetStatistic

func (q *TaskQueue) GetStatistic() *Statistic

func (*TaskQueue) Pop2do

func (q *TaskQueue) Pop2do() (*Task, error)

Peek a task to exec.

func (*TaskQueue) PopDone

func (q *TaskQueue) PopDone() (*Task, error)

Pop Task from done channel.

func (*TaskQueue) Push2doWait

func (q *TaskQueue) Push2doWait(priority Priority, execTimeout time.Duration, dataPtr interface{})

Wait until pushed.

func (*TaskQueue) PushDone

func (q *TaskQueue) PushDone(id string, err error)

Tell taskQueue some task is done.

Jump to

Keyboard shortcuts

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