queue

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

* @Author: SpenserCai * @Date: 2023-08-16 11:05:15 * @version: * @LastEditors: SpenserCai * @LastEditTime: 2023-08-16 17:05:59 * @Description: file content

* @Author: SpenserCai * @Date: 2023-08-16 13:48:01 * @version: * @LastEditors: SpenserCai * @LastEditTime: 2023-08-16 17:31:19 * @Description: file content

* @Author: SpenserCai * @Date: 2023-08-16 13:55:46 * @version: * @LastEditors: SpenserCai * @LastEditTime: 2023-08-16 17:34:55 * @Description: file content

* @Author: SpenserCai * @Date: 2023-08-16 13:57:27 * @version: * @LastEditors: SpenserCai * @LastEditTime: 2023-08-16 13:57:31 * @Description: file content

Index

Constants

View Source
const (
	// 任务执行成功
	EventSuccess = 0
	// 任务执行失败
	EventFaile = 1
	// 任务被取消
	EventCancel = 2
	// 任务排队中
	EventPendding = 3
	// 任务执行中
	EventRunning = 4
)

枚举事件类型

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionQueue

type ActionQueue struct {
	// 最大并发数
	MaxConcurrent int
	// 当前并发数
	CurrentConcurrent int
	// 任务队列
	TaskQueue chan Task
	// 事件队列
	EventQueue chan EventMessage
	// 任务ID列表
	TaskList []string
	// contains filtered or unexported fields
}

一个执行队列

func NewActionQueue

func NewActionQueue(maxConcurrent int, eventQueue chan EventMessage) *ActionQueue

创建一个执行队列

func (*ActionQueue) AddTask

func (aq *ActionQueue) AddTask(id string, task func() (map[string]interface{}, error), callback func())

向执行队列中添加一个任务

func (*ActionQueue) CancelTask

func (aq *ActionQueue) CancelTask(id string)

根据任务ID取消任务

func (*ActionQueue) GetEvent

func (aq *ActionQueue) GetEvent() EventMessage

获取错误队列中的错误消息

func (*ActionQueue) Run

func (aq *ActionQueue) Run()

执行队列中的任务

type EventMessage

type EventMessage struct {
	ID        string                 `json:"id"`
	EventType int                    `json:"event_type"`
	EventData map[string]interface{} `json:"event_data"`
	Aq        *ActionQueue
}

事件消息

type Task

type Task struct {
	ID       string
	Action   func() (map[string]interface{}, error)
	Callback func()
}

一个执行队列中的任务

Jump to

Keyboard shortcuts

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