feat(monitor): 取消失败发布并修正危险按钮对比度

- Parse-monitor: the batch-retry button rendered red-on-red because
  weknoraMonitor.css overrode the global .danger style with text color
  only; make .danger a filled red button with proper hover/disabled states.
- Add operator cancel: 批量取消所选 / per-task 不再处理 buttons move
  failed/stalled publications to a new 'cancelled' state in one audited
  batch operation (POST /api/v1/test-publications/cancel-batch, idempotent,
  migration 000041 widens the CHECK constraints). Queued upload jobs are
  cancelled, open dead letters abandoned; source records and spool files
  stay intact so re-marking in the catalog can retry later.
- Queue status filter and labels learn 已取消; OpenAPI contract updated.
This commit is contained in:
姚章浩
2026-09-15 17:58:40 +08:00
parent 822896ea6c
commit 5037c05e93
13 changed files with 476 additions and 14 deletions
+54
View File
@@ -161,6 +161,49 @@ func TestHandlerListsJobFailuresAndRunsServerSideBatchRetry(t *testing.T) {
}
}
func TestHandlerRunsServerSideBatchCancel(t *testing.T) {
store := &fakeJobStore{
cancelBatchResult: governance.RetryPublicationsBatchResult{
BatchKey: "op-cancel-1", Total: 2, Started: 1, NotRetryable: 1,
Outcomes: []governance.RetryOutcome{{PublicationID: "tp-1", Result: "cancelled"}, {PublicationID: "tp-x", Result: "not_retryable", Detail: "publication not found"}},
},
}
handler, err := NewHandler(Config{Store: store, Now: func() time.Time { return time.Date(2026, time.September, 3, 9, 0, 0, 0, time.UTC) }})
if err != nil {
t.Fatal(err)
}
recorder := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodPost, "/api/v1/test-publications/cancel-batch",
strings.NewReader(`{"publication_ids":["tp-1","tp-x"],"reason":"源头为空文档,不再重试"}`))
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Idempotency-Key", "op-cancel-1")
handler.ServeHTTP(recorder, request)
if recorder.Code != http.StatusOK {
t.Fatalf("cancel-batch status = %d body %s", recorder.Code, recorder.Body.String())
}
if store.cancelBatchOperation != "op-cancel-1" || store.cancelBatchRequest == nil ||
len(store.cancelBatchRequest.PublicationIDs) != 2 ||
store.cancelBatchRequest.Reason != "源头为空文档,不再重试" || store.cancelBatchRequest.Now.IsZero() {
t.Fatalf("cancel request = %+v op=%q", store.cancelBatchRequest, store.cancelBatchOperation)
}
// Missing Idempotency-Key and missing reason are rejected before touching the store.
recorder = httptest.NewRecorder()
handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, "/api/v1/test-publications/cancel-batch",
strings.NewReader(`{"publication_ids":["tp-1"],"reason":"r"}`)))
if recorder.Code != http.StatusBadRequest {
t.Fatalf("missing key status = %d", recorder.Code)
}
recorder = httptest.NewRecorder()
noReason := httptest.NewRequest(http.MethodPost, "/api/v1/test-publications/cancel-batch",
strings.NewReader(`{"publication_ids":["tp-1"],"reason":""}`))
noReason.Header.Set("Idempotency-Key", "op-cancel-2")
handler.ServeHTTP(recorder, noReason)
if recorder.Code != http.StatusBadRequest {
t.Fatalf("missing reason status = %d", recorder.Code)
}
}
func TestHandlerListsJobsWithJSONPayload(t *testing.T) {
store := &fakeJobStore{listResult: []jobs.Job{{
ID: "job-6",
@@ -1438,6 +1481,11 @@ type fakeJobStore struct {
retryBatchRequest *governance.RetryPublicationsBatchRequest
retryBatchOperation string
retryBatchResult governance.RetryPublicationsBatchResult
cancelBatchRequest *governance.CancelPublicationsBatchRequest
cancelBatchOperation string
cancelBatchResult governance.RetryPublicationsBatchResult
cancelBatchReplayed bool
cancelBatchErr error
retryBatchReplayed bool
retryBatchErr error
enqueued jobs.EnqueueRequest
@@ -1837,6 +1885,12 @@ func (s *fakeJobStore) RetryPublicationsBatchWithOperation(_ context.Context, re
return s.retryBatchResult, s.retryBatchReplayed, s.retryBatchErr
}
func (s *fakeJobStore) CancelPublicationsBatchWithOperation(_ context.Context, request governance.CancelPublicationsBatchRequest, operationID string) (governance.RetryPublicationsBatchResult, bool, error) {
s.cancelBatchRequest = &request
s.cancelBatchOperation = operationID
return s.cancelBatchResult, s.cancelBatchReplayed, s.cancelBatchErr
}
func (s *fakeJobStore) ListScopeRules(_ context.Context, connectionID string) ([]governance.ScopeRule, error) {
s.scopeRuleConnectionID = connectionID
return s.scopeRules, s.scopeRuleErr