Last active
May 27, 2019 11:02
-
-
Save eugene-s/42fee6844017337a81ed911a3b175681 to your computer and use it in GitHub Desktop.
Celery healthchecks for django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
celery inspect ping -d <worker_name> --timeout=<timeout_time> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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