feat: add generic queue and subscription retirement
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
type Queue struct {
|
||||
// Record 包含命名空间、记录标识、并发版本和 UTC 时间。
|
||||
core.Record
|
||||
// RetiredAt 永久退役的UTC时间;空表示未退役,退役后保留历史且禁止新工作。
|
||||
RetiredAt *time.Time `db:"retired_at"`
|
||||
// Name 可读名称,唯一性范围由对应数据表约束。
|
||||
Name string `db:"name"`
|
||||
// Paused 暂停标记;停止新的受控工作,不表示在途请求已停止。
|
||||
|
||||
@@ -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 == "" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user