Files
contracts/base/res_job.go
T
what 9446571363 重构: base 包资源核心类型迁移到 req/resx,新增 res_watcher/res_api_param
base/resource.go、resource_hooks.go、resource_test.go、query_field.go 删除,ResField 等具体实现搬到 req/resx(见 res_field.go 里的类型别名)。res_listener.go 替换成 res_watcher.go,对应资源变更监听概念改名。新增 res_api_param.go 及配套测试(ResApi 参数建模,给 MCP tool 的 JSON Schema 生成用)。
2026-07-22 09:13:05 +08:00

49 lines
1.7 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 base
import "time"
type ResJob struct {
Uuid string `db:"uuid"`
Code string `db:"code"`
Name string `db:"name"`
ResourceUuid string `db:"resource_uuid"`
MaxAttempts int `db:"maxAttempts"` // 最大重试次数
Concurrent int `db:"concurrent"` // 同类 job 最大并发数,0 表示不限制
Timeout int `db:"timeout"` // 单次执行超时秒数,0 表示不限制
Retry int `db:"retry"` // 重试间隔秒数,0 表示不重试,>0 表示固定间隔秒数
UpdatedAt string `db:"updated_at"`
CreatedAt string `db:"created_at"`
}
type GetResJob func(code string) (ResJob, bool)
const (
FailedJobStatusResolved = 0 // 已解决(成功完成)
FailedJobStatusPending = 1 // 待重试
FailedJobStatusExceeded = 2 // 已超出最大重试次数
FailedJobStatusInterrupted = 3 // shutdown 中断
)
type ResFailedJob struct {
ID int64 `db:"id"`
Queue string `db:"queue"` // 投递队列(ResJob.Code
Payload string `db:"payload"` // JSON
Platform string `db:"platform"`
Saas string `db:"saas"`
TraceId string `db:"trace_id"`
Exception string `db:"exception"`
Attempts int `db:"attempts"`
MaxAttempts int `db:"maxAttempts"`
Status int `db:"status"`
RetryAt *time.Time `db:"retry_at"`
RetriedAt *time.Time `db:"retried_at"`
OwnedUser string `db:"owned_user"` // 触发任务的用户 uuid
CreatedAt string `db:"created_at"`
UpdatedAt string `db:"updated_at"`
}
// CanRetry 是否还可以重试
func (j ResFailedJob) CanRetry() bool {
return j.Status == FailedJobStatusPending && j.Attempts < j.MaxAttempts
}