重构: 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 生成用)。
This commit is contained in:
+36
-2
@@ -1,14 +1,48 @@
|
||||
package base
|
||||
|
||||
import "time"
|
||||
|
||||
type ResJob struct {
|
||||
Uuid string `db:"uuid"`
|
||||
Code string `db:"code"`
|
||||
Name string `db:"name"`
|
||||
ResourceUuid string `db:"resource_uuid"`
|
||||
Replay int64 `db:"replay"`
|
||||
IsRecord bool `db:"isRecord"`
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user