feat(runtime): add bulk purge for archived queue tasks and chat_attachment i18n

Operators can clear all finally-failed tasks in one queue from the runtime
drawer, with audit logging and scoped API access. Also localize the
chat_attachment queue label in the runtime queue details table.
This commit is contained in:
wizardchen
2026-07-23 16:51:09 +08:00
committed by lyingbug
parent de7507cc96
commit 6c794f64cf
18 changed files with 307 additions and 9 deletions
+2
View File
@@ -998,6 +998,8 @@ func RegisterSystemAdminRoutes(
handler.ListRuntimeTasks)
g.apiKeyRoute(adminRoutes, http.MethodPost, "/runtime/queues/:queue/tasks/:task_id/actions/:action",
apiKeyPlatform(types.APIKeyCapabilitySystemRuntimeManage), handler.MutateRuntimeTask)
g.apiKeyRoute(adminRoutes, http.MethodDelete, "/runtime/queues/:queue/archived",
apiKeyPlatform(types.APIKeyCapabilitySystemRuntimeManage), handler.PurgeArchivedRuntimeTasks)
// Bulk action — write the current default-quota setting onto
// every existing tenant. Lives under /tenants instead of
@@ -62,6 +62,7 @@ func TestPlatformControlPlaneRoutesDeclarePlatformCapabilities(t *testing.T) {
{http.MethodPut, "/api/v1/system/admin/settings/:key", types.APIKeyCapabilitySystemSettingsManage},
{http.MethodGet, "/api/v1/system/admin/runtime/queues", types.APIKeyCapabilitySystemRuntimeRead},
{http.MethodPost, "/api/v1/system/admin/runtime/queues/:queue/tasks/:task_id/actions/:action", types.APIKeyCapabilitySystemRuntimeManage},
{http.MethodDelete, "/api/v1/system/admin/runtime/queues/:queue/archived", types.APIKeyCapabilitySystemRuntimeManage},
}
for _, tc := range cases {
policy := mustLookupAPIKeyPolicy(t, g, tc.method, tc.path)
+14
View File
@@ -682,6 +682,20 @@ func (a *asynqTaskInspector) ForceDeleteRuntimeTask(ctx context.Context, queue,
return true, a.inspector.DeleteTask(queue, taskID)
}
// PurgeArchivedRuntimeTasks clears the whole archived (dead-letter) set for one
// queue. asynq's DeleteAllArchivedTasks scopes strictly to the archived list,
// so pending/active/scheduled/retry work is never at risk.
func (a *asynqTaskInspector) PurgeArchivedRuntimeTasks(ctx context.Context, queue string) (int, bool, error) {
if a == nil || a.inspector == nil {
return 0, false, nil
}
deleted, err := a.inspector.DeleteAllArchivedTasks(queue)
if err != nil {
return 0, true, err
}
return deleted, true, nil
}
func (a *asynqTaskInspector) WorkerServerStats(
ctx context.Context,
) ([]types.WorkerServerStat, bool, error) {