feat(system): add failed-task inspection and manual retry for runtime queues
Give system admins visibility into asynq tasks that exhausted retries, with safe retry/delete actions and operator-facing UI in Runtime Queues.
This commit is contained in:
@@ -121,6 +121,12 @@ const (
|
||||
// another user's local password. Details identify the target and record
|
||||
// session revocation, but never contain the old or new password.
|
||||
AuditActionSystemUserPasswordReset AuditAction = "system.user_password_reset"
|
||||
|
||||
// Runtime queue mutations are privileged SystemAdmin actions. Retrying an
|
||||
// archived task can repeat its original side effects; deleting one removes
|
||||
// the Redis failure record. Both must leave a platform audit trail.
|
||||
AuditActionSystemQueueTaskRetried AuditAction = "system.queue_task_retried"
|
||||
AuditActionSystemQueueTaskDeleted AuditAction = "system.queue_task_deleted"
|
||||
)
|
||||
|
||||
// AuditOutcome distinguishes successful mutations from middleware-level
|
||||
|
||||
@@ -38,6 +38,8 @@ func TestAuditAction_DotNamespaceConvention(t *testing.T) {
|
||||
AuditActionSystemAdminPromoted,
|
||||
AuditActionSystemAdminRevoked,
|
||||
AuditActionSystemUserPasswordReset,
|
||||
AuditActionSystemQueueTaskRetried,
|
||||
AuditActionSystemQueueTaskDeleted,
|
||||
}
|
||||
for _, a := range all {
|
||||
s := string(a)
|
||||
@@ -120,6 +122,8 @@ func TestAuditAction_NoCollisionsAcrossNamespaces(t *testing.T) {
|
||||
register("AuditActionSystemAdminPromoted", AuditActionSystemAdminPromoted)
|
||||
register("AuditActionSystemAdminRevoked", AuditActionSystemAdminRevoked)
|
||||
register("AuditActionSystemUserPasswordReset", AuditActionSystemUserPasswordReset)
|
||||
register("AuditActionSystemQueueTaskRetried", AuditActionSystemQueueTaskRetried)
|
||||
register("AuditActionSystemQueueTaskDeleted", AuditActionSystemQueueTaskDeleted)
|
||||
}
|
||||
|
||||
// TestAuditAction_SystemNamespacePrefix pins the system.* actions
|
||||
@@ -134,6 +138,8 @@ func TestAuditAction_SystemNamespacePrefix(t *testing.T) {
|
||||
AuditActionSystemAdminPromoted,
|
||||
AuditActionSystemAdminRevoked,
|
||||
AuditActionSystemUserPasswordReset,
|
||||
AuditActionSystemQueueTaskRetried,
|
||||
AuditActionSystemQueueTaskDeleted,
|
||||
}
|
||||
for _, a := range cases {
|
||||
assert.True(t,
|
||||
@@ -156,6 +162,8 @@ func TestAuditAction_SystemWireValues(t *testing.T) {
|
||||
{AuditActionSystemAdminPromoted, "system.admin_promoted"},
|
||||
{AuditActionSystemAdminRevoked, "system.admin_revoked"},
|
||||
{AuditActionSystemUserPasswordReset, "system.user_password_reset"},
|
||||
{AuditActionSystemQueueTaskRetried, "system.queue_task_retried"},
|
||||
{AuditActionSystemQueueTaskDeleted, "system.queue_task_deleted"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
assert.Equal(t, c.wire, string(c.constant))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
// FailedTaskInfo is the operator-facing projection of an asynq task that
|
||||
// exhausted its automatic retry budget. Payloads are intentionally not
|
||||
// exposed by the SystemAdmin API: they may contain document content or
|
||||
// connector credentials. Only stable routing identifiers are copied out.
|
||||
type FailedTaskInfo struct {
|
||||
ID string `json:"id"`
|
||||
Queue string `json:"queue"`
|
||||
Type string `json:"type"`
|
||||
LastError string `json:"last_error"`
|
||||
LastFailedAt time.Time `json:"last_failed_at"`
|
||||
Retried int `json:"retried"`
|
||||
MaxRetry int `json:"max_retry"`
|
||||
TenantID uint64 `json:"tenant_id,omitempty"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id,omitempty"`
|
||||
KnowledgeID string `json:"knowledge_id,omitempty"`
|
||||
TaskID string `json:"task_id,omitempty"`
|
||||
}
|
||||
@@ -63,3 +63,17 @@ type TaskInspector interface {
|
||||
// capacity and busy workers for each configured pool.
|
||||
WorkerServerStats(ctx context.Context) (stats []types.WorkerServerStat, supported bool, err error)
|
||||
}
|
||||
|
||||
// FailedTaskInspector is the optional operator surface implemented by queue
|
||||
// backends that retain tasks after their automatic retry budget is exhausted.
|
||||
// It is separate from TaskInspector so Lite-mode and test implementations that
|
||||
// only support cancellation/metrics do not need to pretend failed tasks exist.
|
||||
type FailedTaskInspector interface {
|
||||
ListFailedTasks(
|
||||
ctx context.Context,
|
||||
queue string,
|
||||
page, pageSize int,
|
||||
) (tasks []types.FailedTaskInfo, supported bool, err error)
|
||||
RetryFailedTask(ctx context.Context, queue, taskID string) (supported bool, err error)
|
||||
DeleteFailedTask(ctx context.Context, queue, taskID string) (supported bool, err error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user