Skip to content

Summarise the --workers supervisor's state in its log records - #72

Merged
tokibito merged 2 commits into
mainfrom
summarise-supervisor-state
Oct 9, 2026
Merged

tokibito merged 2 commits into
mainfrom
summarise-supervisor-state

Conversation

@tokibito

@tokibito tokibito commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Second half of #65. Each restart under --workers was one record with its delay, and nothing said the whole fleet was down. This adds a summary of the supervisor's state to its log records.

What it does

  • When every worker has exited with an error within ten seconds of starting (the existing threshold for the restart back-off) and none has since run longer than that, the supervisor logs one Every worker is failing to start WARNING with workers and each slot's last exit_codes. One worker failing on its own does not trigger it; its exit records already say so.
  • Once a worker runs for ten seconds again, or exits with code 0, the supervisor logs one Workers recovered INFO with worker_index, pid, failing_for in seconds, and recovered_by (uptime or clean_exit). The WARNING can be logged again if every worker starts failing again later.
  • Supervisor finished gains restarts, the number of workers started in place of one that exited, and abnormal_restarts, the number of those that followed an exit with a code other than 0 or --empty-exit-code. This is the same rule that makes the Worker process exited record a WARNING.

Things to look at

  • A clean exit counts as a recovery. A worker that reaches --max-tasks in less than ten seconds exits with 0 and is restarted at once, so it never runs for ten seconds; without this the state would read "every worker failing" while that worker was processing tasks. The check runs before the restarts in each loop iteration, so that pid names the process that exited rather than its replacement.
  • A slot added with SIGTTIN is not a recovery until it has run for ten seconds or exited cleanly itself; until then it has only not failed yet.
  • _report_exit() now takes its abnormal-exit rule from a shared _abnormal() helper; the existing tests pass unmodified.

Compatibility

Added records and fields only. No logger name, message, existing field or stdout output changes. Existing projects need no changes. The CHANGELOG entry is under Unreleased.

Rebased onto main after #71: the supervisor sets the worker index and counts the restarts in the same _spawn(), and the CHANGELOG has both entries.

Tests

tests/test_supervisor.py gains TestSupervisorState: the WARNING logged once when every worker fails, not logged when only one does, cleared by a worker running past the threshold and by a clean exit (with the exited process's pid), not cleared by a newly added slot, and the restart counts for failing workers, clean exits and a run-once supervisor.

Run on Python 3.13 / Django 6.0 (SQLite), Python 3.14 / Django 6.1 with -W error::DeprecationWarning, and the whole suite against PostgreSQL 16.

Refs #65

Each restart was one record, with nothing that said the whole fleet was
down. The supervisor now logs one "Every worker is failing to start"
WARNING when every slot is failing within the stable window at once, and
a "Workers recovered" INFO once a worker runs past the window again.
"Supervisor finished" gains restarts and abnormal_restarts next to the
exit codes it already lists.

Added records and fields only; no logger name, message, existing field or
stdout output changes.

Refs #65
A worker that reaches --max-tasks sooner than the stable window exits
with code 0 and is restarted at once, so it never ran past the window and
the supervisor kept reporting every worker as failing while that one was
working. A clean exit now clears the state too, and the record says which
of the two cleared it in recovered_by. The check runs before the restarts
so that the record names the process that exited.

Refs #65
@tokibito
tokibito force-pushed the summarise-supervisor-state branch from 88d26b3 to 5423f16 Compare October 9, 2026 05:14
@tokibito
tokibito merged commit 9f4db93 into main Oct 9, 2026
10 checks passed
@tokibito
tokibito deleted the summarise-supervisor-state branch October 9, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant