Skip to content

check_celery_threads

django_spire.celery.management.commands.check_celery_threads

Command

Bases: BaseCommand

help = 'Reports whether the embedded Celery web-process threads are alive, judging each component by the freshness of its claim row. STALE means the thread has not claimed recently (dead, or never started). With --fail, exits 1 when anything is STALE.' class-attribute instance-attribute

add_arguments

Source code in django_spire/celery/management/commands/check_celery_threads.py
def add_arguments(self, parser: CommandParser) -> None:
    parser.add_argument(
        '--max-age',
        type=float,
        default=0,
        help=(
            'Extra staleness grace in seconds, on top of twice the component interval '
            '(or tick) (default: 0).'
        ),
    )
    parser.add_argument(
        '--fail', action='store_true', help='Exit with status 1 when any component is STALE.'
    )

handle

Source code in django_spire/celery/management/commands/check_celery_threads.py
def handle(self, *args, **options) -> None:  # noqa: ARG002
    max_age = float(options['max_age'])
    stale = self._check_sweep(max_age) or self._check_scheduler(max_age)

    if options['fail'] and stale:
        raise SystemExit(1)