refactor(knowledge): route single delete through async pipeline

Reuse enqueueKnowledgeListDelete inside DeleteKnowledge so that single-item
delete shares the same hardening as BatchDeleteKnowledge / ClearKnowledgeBase:
asynq retries, business-aware queue routing, and marking-as-deleting inside
the worker.

The endpoint now returns 200 once the delete task has been enqueued; the
response body carries the asynq task_id and the message is updated to
"Delete task submitted". Swagger annotations, generated docs and the Go
client SDK comment are updated to reflect the new asynchronous semantics.

Note: this is a behavior change. Callers that previously assumed the
knowledge was already gone on a 200 response should poll the task status
or accept eventual consistency, matching the existing BatchDeleteKnowledge
contract.
This commit is contained in:
wizardchen
2026-05-25 16:54:26 +08:00
committed by lyingbug
parent af1f2b469a
commit d12fb42e60
5 changed files with 35 additions and 16 deletions
+3 -1
View File
@@ -353,7 +353,9 @@ func (c *Client) ListKnowledgeWithFilter(ctx context.Context,
return response.Data, response.Total, nil
}
// DeleteKnowledge deletes a knowledge entry by its ID
// DeleteKnowledge enqueues an asynchronous delete for the given knowledge entry.
// The server returns 200 once the task has been submitted; the actual deletion is
// performed by a background worker (same pipeline as BatchDeleteKnowledge).
func (c *Client) DeleteKnowledge(ctx context.Context, knowledgeID string) error {
path := fmt.Sprintf("/api/v1/knowledge/%s", knowledgeID)
resp, err := c.doRequest(ctx, http.MethodDelete, path, nil, nil)