|
| 1 | +--- |
| 2 | +title: Celery task queues |
| 3 | +--- |
| 4 | + |
| 5 | +# Celery task queues |
| 6 | + |
| 7 | +This document covers inspecting and managing Celery task queues in the deployed |
| 8 | +Packit service. |
| 9 | + |
| 10 | +## Queue overview |
| 11 | + |
| 12 | +The service uses three Celery queues: |
| 13 | + |
| 14 | +- `short-running` - default queue for quick tasks |
| 15 | +- `long-running` - for operations requiring running local commands/sandcastle use (builds, sync-release) |
| 16 | +- `rate-limited` - for tasks re-queued due to API rate limits |
| 17 | + |
| 18 | +Tasks are stored in Valkey (Redis-compatible) database. All tasks use |
| 19 | +[`acks_late=True`](https://docs.celeryq.dev/en/stable/userguide/tasks.html#Task.acks_late), |
| 20 | +meaning tasks are acknowledged after completion. This means in-flight tasks |
| 21 | +have their messages tracked in Valkey until the worker finishes processing them. |
| 22 | + |
| 23 | +## Inspecting queue size and content |
| 24 | + |
| 25 | +### Using Flower (Web UI) |
| 26 | + |
| 27 | +Flower is deployed for monitoring Celery workers and tasks. It's exposed as a |
| 28 | +Service (not a Route), so you need to port-forward to access it: |
| 29 | + |
| 30 | +``` |
| 31 | +$ oc port-forward svc/flower 5555:5555 |
| 32 | +``` |
| 33 | + |
| 34 | +Then open http://localhost:5555 in your browser. |
| 35 | + |
| 36 | +Flower shows: |
| 37 | + |
| 38 | +- Active, processed, and failed tasks |
| 39 | +- Worker status and statistics |
| 40 | +- Task details and results |
| 41 | + |
| 42 | +See [Flower documentation](https://flower.readthedocs.io/en/latest/) for more |
| 43 | +details. |
| 44 | + |
| 45 | +### Using Celery inspect commands |
| 46 | + |
| 47 | +You can also use Celery's built-in inspection to see active/scheduled tasks: |
| 48 | + |
| 49 | +``` |
| 50 | +$ oc exec packit-worker-short-running-0 -- celery -A packit_service.worker.tasks inspect active |
| 51 | +$ oc exec packit-worker-short-running-0 -- celery -A packit_service.worker.tasks inspect reserved |
| 52 | +$ oc exec packit-worker-short-running-0 -- celery -A packit_service.worker.tasks inspect scheduled |
| 53 | +``` |
| 54 | + |
| 55 | +See [Celery Workers Guide - Inspecting workers](https://docs.celeryq.dev/en/stable/userguide/workers.html#inspecting-workers) |
| 56 | +for more inspection commands. |
| 57 | + |
| 58 | +## Purging the task queue |
| 59 | + |
| 60 | +After a long outage, the task queue may accumulate too many stale tasks that no |
| 61 | +longer make sense to process. This section describes how to safely purge the |
| 62 | +queue. |
| 63 | + |
| 64 | +**Important:** Purging while workers are actively processing tasks can cause |
| 65 | +issues - workers may fail to acknowledge completed tasks, potentially leading |
| 66 | +to duplicate processing on restart. |
| 67 | + |
| 68 | +### Safe purge |
| 69 | + |
| 70 | +1. **Optionally scale down workers** to reduce the number of prefetched tasks: |
| 71 | + |
| 72 | + ``` |
| 73 | + $ oc scale statefulset/packit-worker-short-running --replicas=0 |
| 74 | + $ oc scale statefulset/packit-worker-long-running --replicas=1 |
| 75 | + ``` |
| 76 | + |
| 77 | +2. **Purge the queues** using Celery's built-in |
| 78 | + [`purge`](https://docs.celeryq.dev/en/stable/reference/cli.html#celery-purge) |
| 79 | + command. This can be run from any worker pod and will purge all queues: |
| 80 | + |
| 81 | + ``` |
| 82 | + $ oc exec packit-worker-long-running-0 -- celery -A packit_service.worker.tasks purge -Q short-running,long-running,rate-limited |
| 83 | + ``` |
| 84 | + |
| 85 | + Using `-f` flag skips the confirmation prompt. With `-Q` you can also specify only subset of queues. |
| 86 | + |
| 87 | +3. **Scale workers back up** (if scaled down): |
| 88 | + |
| 89 | + ``` |
| 90 | + $ oc scale statefulset/packit-worker-short-running --replicas=<N> |
| 91 | + $ oc scale statefulset/packit-worker-long-running --replicas=<N> |
| 92 | + ``` |
0 commit comments