Weblate and Redis: Task Queue Consistency During Failed Upgrades
0 reputation · 24 Jan 2023, 19:32 UTC
0 reputation · 24 Jan 2023, 19:32 UTC
A critical boundary exists between the persistent database state and the volatile task queue in Redis. If an upgrade fails mid-process, the database may be rolled back to a previous snapshot, but the Redis queue may still contain serialized tasks generated by the newer, failed version of the application. This creates a mismatch where the restarted service attempts to execute tasks using a schema or API version that no longer exists in the restored database.
What is the documented behavior for purging or reconciling stale Celery tasks in Redis after a failed Weblate upgrade? Is there a mechanism to validate task compatibility against the current database migration state before execution?
33275 reputation · 24 Jan 2023, 20:17 UTC
During an upgrade, if the database rolls back but Redis still holds tasks created by the newer code, Weblate does not automatically reconcile or purge those stale tasks. The only documented mechanism is to manually clear the queue with Celery’s purge command or by deleting Redis keys directly. There is no built‑in Weblate API that validates a task’s signature against the current migration state before a worker attempts to execute it; any mismatch will surface as a runtime exception on the worker side.
python manage.py showmigrations --plan
# If Redis is dedicated to Weblate
celery -A weblate purge
# If Redis is shared, target the specific queue
celery -A weblate purge -Q weblate
Does the Redis instance used by Weblate also serve other services? If so, a blanket purge will delete tasks for those services as well. Specify the queue name in the command or manually delete only the keys matching the Weblate queue pattern.
Weblate relies on Celery for asynchronous work. Celery stores task payloads in Redis as opaque blobs keyed by celery-task-*. When a migration rollback happens, the database schema reverts but Redis is unaffected. Celery workers will still pick up the queued tasks and attempt to import the corresponding task functions. If the function name or its arguments no longer match the restored schema, the worker raises an exception but does not automatically remove the task from the queue. Consequently, the only documented way to avoid running incompatible tasks is to purge the queue manually after ensuring the database is in the correct state.
There is no Weblate‑specific hook that checks a task’s payload against the current migration state before execution. Task design (e.g., idempotent logic, versioned task names) and operator discipline are the only safeguards.
redis-cli --scan --pattern 'celery-task-*'
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.