Celery beat and workers healthchecks.

in #code6 years ago (edited)

celery.png

Helthcheck for celery worker:

This command only works when remote control is enabled.

$ celery inspect ping -d <worker_name> --timeout=<timeout_time>

When a celery worker uses a solo pool, healthcheck waits for the task to finish. In this case, you must increase the timeout waiting for a response.

Helthcheck for celery beat:

I could not find a good solution in the documentation, so I came up with my own.
It works for default celery beat scheduler.

from datetime import datetime, timedelta
import pytz
import shelve

now = datetime.now(tz=pytz.utc)
file_data = shelve.open('celerybeat-schedule') # Name of the file used by PersistentScheduler to store the last run times of periodic tasks. 

for task_name, task in file_data['entries'].items():
    try:
        assert now  < task.last_run_at + task.schedule.run_every
    except AttributeError:
        assert timedelta() < task.schedule.remaining_estimate(task.last_run_at)

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 58695.71
ETH 2633.30
USDT 1.00
SBD 2.49