feat: add generic queue and subscription retirement

This commit is contained in:
2026-09-27 14:39:49 +08:00
parent d54bdd9847
commit c9e877c3f7
53 changed files with 1013 additions and 88 deletions

View File

@@ -196,6 +196,17 @@ func (s *Service) ConfigureQueue(ctx context.Context, token auth.Token, id core.
return s.store.ConfigureQueue(ctx, token, id, key, in)
}
// RetireQueue 只关闭已结清的通用资源,不删除任务、交付或审计。
func (s *Service) RetireQueue(ctx context.Context, t auth.Token, id core.ID, key string, in RetireQueueInput) (QueueResult, error) {
if err := ValidateKey(key); err != nil {
return QueueResult{}, err
}
if id.Validate() != nil || in.ExpectedRevision == 0 || strings.TrimSpace(in.Reason) == "" || !utf8.ValidString(in.Reason) || utf8.RuneCountInString(in.Reason) > 1024 {
return QueueResult{}, fault.Invalid("queue id, revision and reason are required")
}
return s.store.RetireQueue(ctx, t, id, key, in)
}
// ValidateConcurrencyKey 不归一化资源键,字节精确相等才共享许可。
func ValidateConcurrencyKey(key string) error {
if key == "" {

View File

@@ -181,6 +181,8 @@ type QueueInput struct {
RatePerSecond uint32 `json:"rate_per_second"`
}
type QueueView struct {
// RetiredAt 永久退役时间;为空表示仍可使用,历史查询保持可用。
RetiredAt *time.Time `json:"retired_at,omitempty"`
// MaxUnfinishedTasks 未终结任务上限,包含待核查;只限制新的受理。
MaxUnfinishedTasks uint32 `json:"max_unfinished_tasks"`
// UnfinishedTasks 当前未终结任务数,JSON 十进制字符串;运行计数不改变配置版本。
@@ -217,6 +219,12 @@ type QueueConfigInput struct {
MaxUnfinishedTasks uint32 `json:"max_unfinished_tasks"`
}
// RetireQueueInput 永久关闭已结清的队列,保留全部历史。
type RetireQueueInput struct {
ExpectedRevision uint64 `json:"expected_revision,string"` // ExpectedRevision 当前队列配置版本。
Reason string `json:"reason"` // Reason 退役原因,写入不可变审计。
}
type QueueResult struct {
// Queue 本次操作返回的队列快照。
Queue QueueView `json:"queue"`
@@ -237,6 +245,7 @@ type Store interface {
ListTasks(context.Context, auth.Token, ListInput) (TaskPage, error)
CancelTask(context.Context, auth.Token, core.ID, string, CancelInput) (CancelResult, error)
CreateQueue(context.Context, auth.Token, string, QueueInput) (QueueResult, error)
RetireQueue(context.Context, auth.Token, core.ID, string, RetireQueueInput) (QueueResult, error)
ConfigureQueue(context.Context, auth.Token, core.ID, string, QueueConfigInput) (QueueResult, error)
GetQueue(context.Context, auth.Token, core.ID) (QueueView, error)
ListTaskAttempts(context.Context, auth.Token, core.ID, HistoryPageInput) (AttemptPage, error)