django-q-watchdog: catch django-q tasks that were lost when a worker died, or froze

Hi all,

I’ve released django-q-watchdog, a small add-on for django-q and django-q2.

The problem: when a django-q worker process dies mid-task (out-of-memory kill, segfault, container restart), the task disappears. There’s no Failed task and no error, only a log line saying “reincarnated worker … after death”. On django-q 1.3.x the same happens when a task hits the timeout. And a task that hangs looks exactly like one that’s working.

django-q-watchdog keeps a heartbeat for every running task and reports:

  • lost and timed out tasks, by name, with the worker, memory and CPU at the time, saved into django-q’s Failed tasks
  • frozen tasks: memory hasn’t moved for an hour, reported as waiting (no CPU, usually an external call with no timeout) or busy (possibly a loop)

A management command (manage.py qwatchdog --fail-on-problems) runs from cron and alerts once per problem through logging and Django signals, and there’s an optional staff-only JSON status endpoint. It works with or without django-tenants.

I built it after losing tasks in production without any trace. It’s tested on django-q 1.3.9 and django-q2 with Django 4.2 to 6.0, including runs where worker processes are killed for real.

GitHub: GitHub - pradeeppc/django-q-watchdog: Find the django-q tasks that crashed, timed out or froze, and say which ones. · GitHub
PyPI: Client Challenge

Feedback is very welcome, especially from people running django-q at scale.