Files
orbit/pulse/model/task.go

69 lines
3.6 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 model
import (
"time"
core "git.yuntuo.hk/k2safe/orbit/model"
)
// Task 表示任务主记录,执行尝试另存历史,终态不自动回退。
// 对应表 pulse_tasks;这是服务端持久化模型,不直接作为 API 响应。
type Task struct {
// Record 包含命名空间、记录标识、并发版本和 UTC 时间。
core.Record
// QueueID 任务所属队列,必须属于同一命名空间。
QueueID core.ID `db:"queue_id"`
// GateID 可选执行门控;为空表示没有流程级门控,仍受队列与权限控制。
GateID *core.ID `db:"gate_id"`
// State 任务状态;与执行尝试状态分开,未知业务效果进入待核查。
State TaskState `db:"state"`
// Handler 业务 Worker 注册的处理器名称。
Handler string `db:"handler"`
// HandlerVersion 处理器兼容版本,受理后不得静默替换。
HandlerVersion string `db:"handler_version"`
// PayloadVersion 输入参数的解释版本。
PayloadVersion string `db:"payload_version"`
// Payload 版本化输入或事件内容;仅承载通用 JSON,不解释行业规则。
Payload core.JSON `db:"payload"`
// Result 已保存的结果或结果引用 JSON;未取得结果时为空。
Result core.JSON `db:"result"`
// PolicySnapshot 受理时冻结的实际生效策略 JSON。
PolicySnapshot core.JSON `db:"policy_snapshot"`
// RecoverySafety 恢复安全等级;未知值按需要核查处理,不能默认自动重跑。
RecoverySafety RecoverySafety `db:"recovery_safety"`
// BusinessKey 业务侧关联键,用于检索追踪,不自动提供业务幂等;可为空,表示尚未设置该关联或值。
BusinessKey *string `db:"business_key"`
// OwnerKind 来源资源类型,例如流程激活;为空表示无来源关联。
OwnerKind *string `db:"owner_kind"`
// OwnerID 来源资源标识,必须与来源类型同时有值或同时为空。
OwnerID *core.ID `db:"owner_id"`
// Priority 同一调度范围内的优先级,不承诺跨队列全局顺序。
Priority int16 `db:"priority"`
// AvailableAt 最早可被领取或处理的时间,统一 UTC。
AvailableAt time.Time `db:"available_at"`
// StartDeadlineAt 最晚允许新尝试开始的时间;为空时仅受总时限约束。
StartDeadlineAt *time.Time `db:"start_deadline_at"`
// DeadlineAt 总截止时间,统一 UTC;到期不能证明外部业务没有生效。
DeadlineAt time.Time `db:"deadline_at"`
// AttemptTimeoutMS 单次尝试的超时时长,单位毫秒。
AttemptTimeoutMS uint64 `db:"attempt_timeout_ms"`
// MaxAttempts 最多执行尝试数,包含首次尝试。
MaxAttempts uint32 `db:"max_attempts"`
// AttemptCount 已产生的执行尝试数,恢复时不得重置。
AttemptCount uint32 `db:"attempt_count"`
// CurrentAttemptID 当前关联的执行尝试,必须属于本任务;可为空,表示尚未设置该关联或值。
CurrentAttemptID *core.ID `db:"current_attempt_id"`
// LeaseEpoch 递增的执行或消费代次,用于隔离旧授权。
LeaseEpoch uint64 `db:"lease_epoch"`
// LeaseUntil 当前执行授权截止时间;没有有效授权时为空。
LeaseUntil *time.Time `db:"lease_until"`
// CancelRequestedAt 取消意图的持久化时间;不等于取消已完成;可为空,表示尚未设置该关联或值。
CancelRequestedAt *time.Time `db:"cancel_requested_at"`
// RetryOf 来源记录标识,人工重新发起时用于保留历史关联;可为空,表示尚未设置该关联或值。
RetryOf *core.ID `db:"retry_of"`
// CompletedAt 终结时间;非终态为空,进入终态时必须写入。
CompletedAt *time.Time `db:"completed_at"`
}
func (Task) TableName() string { return "pulse_tasks" }