Files
pig-farm-controller/internal/infra/models/schedule.go

33 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package models
import (
"time"
)
// PendingTask 是一个待执行任务队列, 里面会储存待执行的Task以及这个Task什么时候执行
// 它是一个纯粹的工作队列,任务被认领后即被删除。
type PendingTask struct {
// 手动填充必须字段以实现硬删除,不内嵌 gorm.Model
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
// 业务字段
// TaskID 使用 int 类型以容纳特殊的负数ID代表系统任务
TaskID int `gorm:"index"`
ExecuteAt time.Time `gorm:"index"` // 任务执行时间
TaskExecutionLogID uint `gorm:"unique;not null"` // 对应的执行历史记录ID
// 关联关系定义
// 通过 TaskExecutionLogID 关联到唯一的 TaskExecutionLog 记录
// ON DELETE CASCADE 确保如果日志被删除,这个待办任务也会被自动清理
TaskExecutionLog TaskExecutionLog `gorm:"foreignKey:TaskExecutionLogID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}
// TableName 自定义 GORM 使用的数据库表名
func (PendingTask) TableName() string {
return "pending_tasks"
}