taskQueue

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending  = 0 // 待处理
	StatusRunning  = 1 // 处理中
	StatusSuccess  = 2 // 处理成功
	StatusFailed   = 3 // 处理失败
	StatusRetrying = 4 // 重试中
)

任务状态常量

Variables

This section is empty.

Functions

func Create

func Create(entity *Entity) error

func IncrementRetryCount

func IncrementRetryCount(id uint64) error

IncrementRetryCount 增加重试次数

func Save

func Save(entity *Entity) error

func UpdateStatus

func UpdateStatus(id uint64, status uint8, err error) error

UpdateStatus 更新任务状态

Types

type Entity

type Entity struct {
	Id          uint64    `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`
	Type        string    `gorm:"column:type;type:varchar(50);not null;" json:"type"`                    // 任务类型
	Status      uint8     `gorm:"column:status;type:tinyint;not null;default:0;index" json:"status"`     // 任务状态
	TaskJson    string    `gorm:"column:task_json;type:text;" json:"taskJson"`                           // 任务数据
	RetryCount  uint8     `gorm:"column:retry_count;type:tinyint;not null;default:0;" json:"retryCount"` // 重试次数
	LastError   string    `gorm:"column:last_error;type:text;" json:"lastError"`                         // 最后一次错误信息
	CreatedAt   time.Time `gorm:"column:created_at;index;autoCreateTime;<-:create;" json:"createdAt"`
	ProcessedAt time.Time `gorm:"column:processed_at;type:datetime;" json:"processedAt"` // 处理时间
}

func GetPendingTasks

func GetPendingTasks(limit int) (tasks []*Entity)

GetPendingTasks 获取待处理的任务

func (*Entity) TableName

func (itself *Entity) TableName() string

Jump to

Keyboard shortcuts

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