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:
@@ -94,6 +94,7 @@ type Store interface {
|
||||
RetryPublicationWithOperation(ctx context.Context, publicationID string, now time.Time, operationID string) (bool, error)
|
||||
ListJobFailures(ctx context.Context, filter governance.JobFailureFilter) (governance.JobFailurePage, error)
|
||||
RetryPublicationsBatchWithOperation(ctx context.Context, request governance.RetryPublicationsBatchRequest, operationID string) (governance.RetryPublicationsBatchResult, bool, error)
|
||||
CancelPublicationsBatchWithOperation(ctx context.Context, request governance.CancelPublicationsBatchRequest, operationID string) (governance.RetryPublicationsBatchResult, bool, error)
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -385,6 +386,9 @@ func NewHandler(config Config) (http.Handler, error) {
|
||||
mux.HandleFunc("POST /api/v1/test-publications/retry-batch", func(w http.ResponseWriter, r *http.Request) {
|
||||
retryPublicationsBatch(w, r, config)
|
||||
})
|
||||
mux.HandleFunc("POST /api/v1/test-publications/cancel-batch", func(w http.ResponseWriter, r *http.Request) {
|
||||
cancelPublicationsBatch(w, r, config)
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/job-failures", func(w http.ResponseWriter, r *http.Request) {
|
||||
listJobFailures(w, r, config.Store)
|
||||
})
|
||||
@@ -1914,6 +1918,50 @@ func retryPublicationsBatch(w http.ResponseWriter, r *http.Request, config Confi
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": result, "operation": operation})
|
||||
}
|
||||
|
||||
func cancelPublicationsBatch(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
operationID, ok := requireOperationID(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var input startTestPublicationsInput
|
||||
if err := decodeStrictJSON(r, &input); err != nil || len(input.PublicationIDs) == 0 || len(input.PublicationIDs) > 100 {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid cancel batch"})
|
||||
return
|
||||
}
|
||||
reason := strings.TrimSpace(input.Reason)
|
||||
if reason == "" || len(reason) > 500 {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "reason is required"})
|
||||
return
|
||||
}
|
||||
seen := make(map[string]bool, len(input.PublicationIDs))
|
||||
for _, publicationID := range input.PublicationIDs {
|
||||
if !validCatalogID(publicationID) || seen[publicationID] {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid publication_ids"})
|
||||
return
|
||||
}
|
||||
seen[publicationID] = true
|
||||
}
|
||||
result, replayed, err := config.Store.CancelPublicationsBatchWithOperation(r.Context(), governance.CancelPublicationsBatchRequest{
|
||||
PublicationIDs: input.PublicationIDs,
|
||||
OperatorRef: actorFor(r),
|
||||
Reason: reason,
|
||||
Now: config.Now().UTC(),
|
||||
}, operationID)
|
||||
if errors.Is(err, postgresstore.ErrOperationRequestConflict) {
|
||||
writeJSON(w, http.StatusConflict, map[string]string{"error": "Idempotency-Key conflicts with a different request"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "could not cancel publications"})
|
||||
return
|
||||
}
|
||||
operation := "created"
|
||||
if replayed {
|
||||
operation = "replayed"
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": result, "operation": operation})
|
||||
}
|
||||
|
||||
func retryPublication(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
operationID, ok := requireOperationID(w, r)
|
||||
if !ok {
|
||||
@@ -1977,7 +2025,7 @@ func decodeStrictJSON(r *http.Request, destination any) error {
|
||||
|
||||
func validProcessingState(state string) bool {
|
||||
switch state {
|
||||
case "planned", "pending", "processing", "finalizing", "completed", "failed", "stalled":
|
||||
case "planned", "pending", "processing", "finalizing", "completed", "failed", "stalled", "cancelled":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user