Monitor Celery beat tasks with HookPulse check-ins
The task checks in when it ends and reports the failure when it raises. Celery beat runs it on a schedule.
Updated
1Create the monitor
Add a routine named celery-task and set how often the job runs. Its page shows the check-in URL: use it in place of https://hookpulse.net/in/YOUR_ID.
2Check in from the task
The task calls the check-in URL with the Python standard library, so it needs no extra package.
# tasks.py
import urllib.request
from celery import shared_task
HOOKPULSE_URL = "https://hookpulse.net/in/YOUR_ID"
def check_in(path=""):
urllib.request.urlopen(HOOKPULSE_URL + path, timeout=10)
@shared_task
def nightly_backup():
try:
run_backup()
check_in()
except Exception:
check_in("/fail")
raise3Schedule it with Celery beat
Add the entry to the beat schedule of your Celery app, and run a beat process next to the workers.
# celery.py, where the Celery app is defined
from celery.schedules import crontab
app.conf.beat_schedule = {
"nightly-backup": {
"task": "tasks.nightly_backup",
"schedule": crontab(hour=3, minute=0),
},
}4Run it once
Call nightly_backup.delay() once from a shell. The routine shows the first check-in. From then on, a missed or failed run sends the alert.