fix(generation): repair articles stuck in generating when latest task is terminal
The state-consistency worker now detects articles still flagged as generating whose latest generation_task is already failed or completed (with a version) and aligns the article status to the terminal task, invalidating article caches on the way out. Adds supporting partial indexes and switches UpdateGenerationTaskStatus to COALESCE started_at and completed_at so partial status updates don't wipe the timestamps.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS idx_articles_generating_state_repair;
|
||||
DROP INDEX IF EXISTS idx_generation_tasks_article_latest_state_repair;
|
||||
DROP INDEX IF EXISTS idx_generation_tasks_recent_terminal_state_repair;
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_generation_tasks_recent_terminal_state_repair
|
||||
ON generation_tasks(updated_at DESC, id DESC)
|
||||
WHERE article_id IS NOT NULL
|
||||
AND status IN ('failed', 'completed');
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_generation_tasks_article_latest_state_repair
|
||||
ON generation_tasks(article_id, tenant_id, created_at DESC, id DESC)
|
||||
WHERE article_id IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_articles_generating_state_repair
|
||||
ON articles(id, tenant_id)
|
||||
WHERE generate_status = 'generating'
|
||||
AND deleted_at IS NULL;
|
||||
Reference in New Issue
Block a user