Skip to content

Instantly share code, notes, and snippets.

@eugene-s
Last active May 27, 2019 11:02
Show Gist options
  • Save eugene-s/42fee6844017337a81ed911a3b175681 to your computer and use it in GitHub Desktop.
Save eugene-s/42fee6844017337a81ed911a3b175681 to your computer and use it in GitHub Desktop.
Celery healthchecks for django
celery inspect ping -d <worker_name> --timeout=<timeout_time>
from datetime import datetime, timedelta
import celery
import pytz
from celery.beat import Service
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Celery beat healthcheck'
def handle(self, *args, **options):
schedule = Service(celery.current_app).get_scheduler().get_schedule()
now = datetime.now(tz=pytz.utc)
for task_name, task in schedule.items():
try:
assert now < task.last_run_at + task.schedule.run_every
except AttributeError:
assert timedelta() < task.schedule.remaining_estimate(task.last_run_at)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment