Files
knowledge-governance/internal/governance/job_failures.go
T
姚章浩 5037c05e93 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.
2026-09-30 10:54:07 +08:00

84 lines
2.9 KiB
Go

package governance
import "time"
// JobFailure is one terminal-attempt dead-letter projection (P6). It never
// replaces the original jobs audit row; it points at it.
type JobFailure struct {
ID string `json:"id"`
JobID string `json:"job_id"`
JobType string `json:"job_type"`
PublicationID string `json:"publication_id,omitempty"`
SourceItemID string `json:"source_item_id,omitempty"`
ErrorCode string `json:"error_code"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"max_attempts_at_failure"`
ChangeSetID string `json:"change_set_id,omitempty"`
Action string `json:"action,omitempty"`
TargetKBID string `json:"target_kb_id,omitempty"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
DocName string `json:"doc_name,omitempty"`
LastError string `json:"last_error,omitempty"`
}
type JobFailureFilter struct {
State string // open | requeued | abandoned | "" (defaults to open)
Limit int
Offset int
}
type JobFailurePage struct {
Items []JobFailure `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
const (
RetryStarted = "started"
RetryAlreadyRunning = "already_running"
RetryNotRetryable = "not_retryable"
)
// RetryPublicationsBatchRequest is the server-side batch retry (P6): one
// atomic operation covering 1..100 publications with per-item outcomes.
type RetryPublicationsBatchRequest struct {
PublicationIDs []string `json:"publication_ids"`
OperatorRef string `json:"operator_ref"`
Reason string `json:"reason"`
Now time.Time `json:"-"`
}
type RetryOutcome struct {
PublicationID string `json:"publication_id"`
Result string `json:"result"`
Detail string `json:"detail,omitempty"`
}
type RetryPublicationsBatchResult struct {
BatchKey string `json:"batch_key"`
Total int `json:"total"`
Started int `json:"started"`
AlreadyRunning int `json:"already_running"`
NotRetryable int `json:"not_retryable"`
Outcomes []RetryOutcome `json:"outcomes"`
}
// CancelOutcome constants reuse the retry vocabulary plus "cancelled".
const (
CancelCancelled = "cancelled"
)
// CancelPublicationsBatchRequest is the operator's "stop retrying" batch:
// 1..100 failed/stalled publications move to 'cancelled', their queued
// upload jobs are dropped and their open dead letters are abandoned.
// Source records and spooled artifacts are untouched; re-marking the file
// in 来源与目录 can still create a fresh publication later.
type CancelPublicationsBatchRequest struct {
PublicationIDs []string `json:"publication_ids"`
OperatorRef string `json:"operator_ref"`
Reason string `json:"reason"`
Now time.Time `json:"-"`
}