I'm using Celery with Django for an online game.
I've written middleware to check whether Celery is available and running, based on this answer: Detect whether Celery is Available/Running
My code actually looks like this:
from celery.task.control import inspect
class CeleryCheckMiddleware(object):
def process_request(self, request):
insp = inspect().stats()
if not insp:
return render(...)
else:
return None
But I forgot the caveat in the comment at the bottom of that answer, 'I've discovered that the above adds two reply.celery.pidbox queues to rabbitmq every time it's run. This leads to an incremental increase in rabbitmq's memory usage.'
I'm now (only one day later!) noticing occasional 500 errors starting from the line insp = inspect().stats()
and terminating with OSError: [Errno 4] Interrupted system call
.
Is there a memory-safe way to check whether Celery is available and running?