fix(tasks): dequeue work for deleted knowledge bases
This commit is contained in:
@@ -64,6 +64,24 @@ type TaskInspector interface {
|
||||
WorkerServerStats(ctx context.Context) (stats []types.WorkerServerStat, supported bool, err error)
|
||||
}
|
||||
|
||||
// KnowledgeBaseTaskCanceller is the optional queue-cleanup capability used
|
||||
// when a knowledge base is deleted. It is separate from TaskInspector so
|
||||
// lightweight test doubles and queue backends that cannot inspect tasks do
|
||||
// not need to implement knowledge-base-wide scanning.
|
||||
type KnowledgeBaseTaskCanceller interface {
|
||||
// CancelTasksForKnowledgeBase removes pending/scheduled/retry tasks
|
||||
// associated with kbID and signals matching active workers to stop.
|
||||
// knowledgeIDs covers batch tasks whose payload references documents but
|
||||
// does not carry the parent knowledge-base ID. dataSourceIDs covers sync
|
||||
// tasks whose payload only identifies a data source.
|
||||
CancelTasksForKnowledgeBase(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
knowledgeIDs []string,
|
||||
dataSourceIDs []string,
|
||||
) (deleted int, cancelled int, err error)
|
||||
}
|
||||
|
||||
// RuntimeTaskInspector is the optional operator surface implemented by queue
|
||||
// backends that retain inspectable task state. It is separate from
|
||||
// TaskInspector so Lite mode and light-weight tests do not need to implement
|
||||
|
||||
@@ -83,6 +83,23 @@ type TaskPendingOpsRepository interface {
|
||||
DeleteByDedupKey(ctx context.Context, taskType, scope, scopeID, dedupKey, op string) error
|
||||
}
|
||||
|
||||
// TaskPendingOpsScopeCleaner is an optional extension for callers that need
|
||||
// to discard every durable pending operation owned by a deleted scope. It is
|
||||
// intentionally separate from TaskPendingOpsRepository so alternate queue
|
||||
// implementations and existing test doubles are not forced to implement a
|
||||
// lifecycle-only operation.
|
||||
type TaskPendingOpsScopeCleaner interface {
|
||||
DeleteByScope(ctx context.Context, scope, scopeID string) error
|
||||
}
|
||||
|
||||
// TaskPendingOpsKnowledgeBaseGuard atomically persists a KB-scoped operation
|
||||
// only while its knowledge base is still active. Implementations must
|
||||
// serialize the active-KB check with soft deletion so a detached worker cannot
|
||||
// recreate durable work after the deletion scrub has finished.
|
||||
type TaskPendingOpsKnowledgeBaseGuard interface {
|
||||
EnqueueIfKnowledgeBaseActive(ctx context.Context, op *types.TaskPendingOp) (accepted bool, err error)
|
||||
}
|
||||
|
||||
// TaskDeadLetterRepository persists rows for the generic task dead-letter
|
||||
// archive (`task_dead_letters`). Two writers exist: the asynq
|
||||
// dead-letter middleware (one row per archived asynq task), and the
|
||||
|
||||
@@ -396,6 +396,7 @@ type KBDeletePayload struct {
|
||||
TracingContext
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
DataSourceIDs []string `json:"data_source_ids,omitempty"`
|
||||
EffectiveEngines []RetrieverEngineParams `json:"effective_engines"`
|
||||
// VectorStoreID is the bound store snapshot taken at enqueue time (before
|
||||
// soft-delete) so the async worker can resolve the right store. nil means
|
||||
|
||||
Reference in New Issue
Block a user