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:
@@ -83,6 +83,9 @@ type runtimeTaskTestInspector struct {
|
||||
retriedTask string
|
||||
deletedTask string
|
||||
forceDeleted string
|
||||
purgedQueue string
|
||||
purgedCount int
|
||||
purgeErr error
|
||||
cancelKnowledge string
|
||||
cancelDeleted int
|
||||
mutatedQueue string
|
||||
@@ -193,6 +196,16 @@ func (r *runtimeTaskTestInspector) ForceDeleteRuntimeTask(
|
||||
return true, r.forceDeleteErr
|
||||
}
|
||||
|
||||
func (r *runtimeTaskTestInspector) PurgeArchivedRuntimeTasks(
|
||||
_ context.Context, queue string,
|
||||
) (int, bool, error) {
|
||||
r.purgedQueue = queue
|
||||
if r.purgeErr != nil {
|
||||
return 0, true, r.purgeErr
|
||||
}
|
||||
return r.purgedCount, true, nil
|
||||
}
|
||||
|
||||
func TestGetRuntimeQueuesReportsIsolatedPoolCapacity(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
handler := &SystemHandler{
|
||||
@@ -399,6 +412,46 @@ func TestRuntimeTaskMutationsDelegateToInspector(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurgeArchivedRuntimeTasksDelegatesToInspector(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
inspector := &runtimeTaskTestInspector{purgedCount: 7}
|
||||
handler := &SystemHandler{taskInspector: inspector}
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Params = gin.Params{{Key: "queue", Value: types.QueueChatAttachment}}
|
||||
ctx.Request = httptest.NewRequest(http.MethodDelete, "/archived", nil)
|
||||
|
||||
handler.PurgeArchivedRuntimeTasks(ctx)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
if inspector.purgedQueue != types.QueueChatAttachment {
|
||||
t.Fatalf("purged queue = %q, want %q", inspector.purgedQueue, types.QueueChatAttachment)
|
||||
}
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if response["deleted"] != float64(7) {
|
||||
t.Fatalf("deleted = %v, want 7", response["deleted"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurgeArchivedRuntimeTasksRejectsUnknownQueue(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
handler := &SystemHandler{taskInspector: &runtimeTaskTestInspector{}}
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Params = gin.Params{{Key: "queue", Value: "unknown"}}
|
||||
ctx.Request = httptest.NewRequest(http.MethodDelete, "/archived", nil)
|
||||
|
||||
handler.PurgeArchivedRuntimeTasks(ctx)
|
||||
if recorder.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status = %d, want %d", recorder.Code, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListRuntimeTasksRejectsUnknownQueue(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
handler := &SystemHandler{taskInspector: &runtimeTaskTestInspector{}}
|
||||
|
||||
Reference in New Issue
Block a user