Files
orbit/weave/instance/details.go

56 lines
4.1 KiB
Go
Raw Permalink 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 instance
import (
"context"
"encoding/json"
"time"
"git.yuntuo.hk/k2safe/orbit/internal/fault"
core "git.yuntuo.hk/k2safe/orbit/model"
"git.yuntuo.hk/k2safe/orbit/platform/auth"
)
// StepDetail 只读取一个当前激活的输入输出,避免步骤列表聚合大载荷。
type StepDetail struct {
InstanceID core.ID `json:"instance_id"` // InstanceID 授权实例。
Revision uint64 `json:"revision,string"` // Revision 与本次步骤详情同一快照的实例版本。
Step StepView `json:"step"` // Step 当前步骤与激活身份。
Input json.RawMessage `json:"input,omitempty"` // Input 当前激活输入,未激活时省略,显式null仍保留。
Output json.RawMessage `json:"output,omitempty"` // Output 当前激活已有结果,尚无结果时省略。
ActivatedAt *time.Time `json:"activated_at,omitempty"` // ActivatedAt 当前激活创建时间,不代表等待预算重新开始。
CompletedAt *time.Time `json:"completed_at,omitempty"` // CompletedAt 当前激活结束时间;核查或进行中可能为空。
Poll *PollView `json:"poll,omitempty"` // Poll 当前激活的查询预算及最后任务,仅POLL有值。
Wait *WaitView `json:"wait,omitempty"` // Wait 当前信号/定时/最终信号等待,原截止不会因换代延长。
}
type PollView struct {
UsedRounds uint32 `json:"used_rounds"` // UsedRounds 已用业务轮编号,跨恢复激活累计。
FirstRound uint32 `json:"first_round"` // FirstRound 本激活继承的首个业务轮。
FirstRoundAttemptsUsed uint32 `json:"first_round_attempts_used"` // FirstRoundAttemptsUsed 该轮此前激活实际已用请求尝试。
MaxRounds uint32 `json:"max_rounds"` // MaxRounds 固定业务轮上限。
MaxAttemptsPerRound uint32 `json:"max_attempts_per_round"` // MaxAttemptsPerRound 原单轮请求尝试上限。
IntervalMS uint64 `json:"interval_ms"` // IntervalMS 成功PENDING后的原查询间隔,毫秒。
DeadlineAt time.Time `json:"deadline_at"` // DeadlineAt 第一次查询激活确定的绝对截止。
NextPollAt *time.Time `json:"next_poll_at,omitempty"` // NextPollAt 下一业务轮可开始时间;非轮间等待为空。
CurrentTaskID *core.ID `json:"current_task_id,omitempty"` // CurrentTaskID 当前尚待收集结果的查询任务。
LastTaskID core.ID `json:"last_task_id"` // LastTaskID 本激活最后一轮任务,可据此读取执行详情并核查。
ResolvedAt *time.Time `json:"resolved_at,omitempty"` // ResolvedAt 当前查询预算结清时间。
}
type WaitView struct {
ID core.ID `json:"id"` // ID 当前激活等待身份。
Kind string `json:"kind"` // Kind SIGNAL、TIMER或POLL。
State string `json:"state"` // State 等待、满足、过期或取消状态。
Name *string `json:"name,omitempty"` // Name 信号名称;TIMER及未核验的旧等待为空。
PayloadVersion *string `json:"payload_version,omitempty"` // PayloadVersion 冻结信号内容契约。
CorrelationKey string `json:"correlation_key"` // CorrelationKey 原精确关联;TIMER为空字符串。
DeadlineAt time.Time `json:"deadline_at"` // DeadlineAt 首次等待的绝对截止。
WinnerSignalID *core.ID `json:"winner_signal_id,omitempty"` // WinnerSignalID 已选中信号,不表示在途执行已结束。
ResolvedAt *time.Time `json:"resolved_at,omitempty"` // ResolvedAt 等待结清时间。
}
func (s *Service) Step(ctx context.Context, t auth.Token, id core.ID, key string) (StepDetail, error) {
if id.Validate() != nil || !versionName(key) {
return StepDetail{}, fault.Invalid("valid workflow id and step key required")
}
return s.store.Step(ctx, t, id, key)
}