feat(fc2a): add maintenance tasks (recovery + cleanup) with beat schedule

recover_interrupted_tasks runs every 5 minutes, finds ImportTask rows
stuck in 'processing' for >30 minutes (well above any legitimate import
duration), and re-queues them. cleanup_old_tasks runs daily and deletes
finished tasks older than 7 days so the task table stays an operational
view rather than an archive.

Both thresholds match ImageRepo's precedent. The 30-min stuck threshold
is documented inline so a future reader can adjust it intentionally
rather than mistaking it for a 'magic number'.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 12:09:09 -04:00
parent d3bb8c509a
commit 509c19ce86
3 changed files with 162 additions and 0 deletions
+11
View File
@@ -44,6 +44,17 @@ def make_celery() -> Celery:
task_acks_late=True,
worker_prefetch_multiplier=1,
broker_connection_retry_on_startup=True,
beat_schedule={
"recover-interrupted-tasks": {
"task": "backend.app.tasks.maintenance.recover_interrupted_tasks",
"schedule": 300.0, # every 5 minutes
},
"cleanup-old-tasks": {
"task": "backend.app.tasks.maintenance.cleanup_old_tasks",
"schedule": 86400.0, # daily
},
},
timezone="UTC",
)
return app