I am using django, celery and RabbitMQ for a webserver. On my development server everything works fine. However, when I try to run the webserver on my production server with apache2/mod_wsgi every second time I reload the result page I get the following error: 'DisabledBackend' object has no attribute '_get_task_meta_for'
That happens when I try to run the following command:
task_state = <taskname>.AsyncResult(task_id).state
My CeleryConfiguration is as following:
app = Celery('<name>',
broker='amqp://<user>:' + RABBITMQ_PASSWD + '@localhost:5672/<vhost>',
backend='django-db',
task_ignore_result=False,
task_track_started=True,
)
The backend is set and it works exactly every second time. I tried restarting the services, the computer and cleaning the databases. Same problem with different backends. Does anyone have an idea what could cause the problem?
Thank you for your help!
Edit: I already looked at the solutions here: Celery with RabbitMQ: AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for' but I don't think my problem has anything to do with the django setup. On my development server I don't experience any problems. Only on my production server the backend gets "lost" every second time. If I press then reload after I see the error, the webpage is shown correctly. If I press again reload the error is shown again. But I cannot find any reasons. I searched the rabbitmq logs, the apache logs, celery logs but I am not able to identify the reason.
Edit 2: After some more testing, it seems to me that the problem is somehow the apache2/wsgi, because everything works if I use the production server together with the normal celery setup. Only when I switch then to apache/mod_wsgi the error occurs.
Edit 3: The problem is caused by using the WSGIDeaemonprocess as recommended here: https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/modwsgi/. My configuration in virtualhost look like this:
WSGIScriptAlias / <path>/wsgi.py
WSGIDaemonProcess <name> python-home=<path to virtualenv> python-path=<path to django project>
WSGIProcessGroup <name>
WSGIApplicationGroup %{GLOBAL}
I then get the error every second reload. However when I remove these lines and use the following lines outside of the virtualhost configuration, everything is working:
WSGIScriptAlias / <path>/wsgi.py
WSGIPythonHome <path to virtualenv>
WSGIPythonPath <path to django project>