39 lines
1.8 KiB
Go
39 lines
1.8 KiB
Go
package entity
|
|
|
|
import "time"
|
|
|
|
// Callback 回调任务类型(S4·C1)。
|
|
const (
|
|
CallbackTypeReport int8 = 1 // 回执终态推送(账号 report_url)
|
|
CallbackTypeUplink int8 = 2 // 上行消息推送(账号 uplink_url)
|
|
)
|
|
|
|
// Callback 回调任务状态机(S4·C1)。
|
|
const (
|
|
CallbackPending int8 = 0 // 待推送(含退避等待)
|
|
CallbackSent int8 = 1 // 已送达(2xx)
|
|
CallbackDead int8 = 2 // 死信(重试耗尽,可重派)
|
|
)
|
|
|
|
// CallbackTask HTTP 回调推送任务(S4·C1:指数退避+死信可查)。
|
|
// 入队源=report 终态首锁/report 手动配对(EnqueueReport)与 uplink 消费
|
|
// (EnqueueUplink);PushWorker 扫描投递。幂等锚=无(每终态一条;report 侧
|
|
// 由 finalizeDetail 首锁语义天然至多一次,重放由 detail 终态锁定挡住)。
|
|
type CallbackTask struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
AccountID int64 `gorm:"index:idx_cb_account,priority:1" json:"account_id"`
|
|
Type int8 `gorm:"default:1" json:"type"` // 1 回执 2 上行(CallbackType*)
|
|
URL string `gorm:"size:512" json:"url"`
|
|
Payload string `gorm:"type:text" json:"payload"` // 客户回调 JSON 载荷
|
|
Status int8 `gorm:"index:idx_cb_status_retry,priority:1;default:0" json:"status"`
|
|
Attempt int `gorm:"default:0" json:"attempt"`
|
|
NextRetryAt time.Time `gorm:"index:idx_cb_status_retry,priority:2" json:"next_retry_at"`
|
|
LastCode int `json:"last_code"` // 最近一次 HTTP 状态码(0=连接层错误)
|
|
LastErr string `gorm:"size:255" json:"last_err"`
|
|
SentAt *time.Time `json:"sent_at"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_cb_account,priority:2" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
}
|
|
|
|
func (CallbackTask) TableName() string { return "callback_task" }
|