New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Celery task runs within the HTTP request/response cycle instead of worker #1821
Comments
That is because, in debug mode, the celery task is set to run in sync mode. That helps for easier debugging during development. When run the production version ( check the
Settings those values to false, will make Celery queue the jobs. |
Awww thank you. It felt like one of those things where I was the one doing something wrong. I wasn't aware celery could be configured in that fashion. Thank you for the information and feedback. |
The whole point of using docker compose and containers is that you can have development environment as close to production as possible. So making celery tasks sync mode by default is unexpected. I also spent couple of hours trying to understand the behavior. Sure that's because I'm a newbie to celery but isn't that the point of using cookiecutter? I would recommend changing the default behavior to queuing and async, but leave the option to enable sync if debug is needed. |
The default value was actually changed in #1945. This should not be a problem anymore. |
What happened?
Called the
taskapp.debug_task
from within the Django admin'ssave_model
method and the task ran within the HTTP request/response cycle.What should've happened instead?
I would of expected to see this job queued with Celery and see a log entry that the worker ran the task.
Steps to reproduce
[//]: MacOS 10.14, Docker
cookiecutter https://github.com/pydanny/cookiecutter-django
(take all defaults except answerY
to docker and celery.cd my_awesome_project; docker-compose -f local.yml build
my_awesome_project/users/admin.py
and add code that runs celery task toclass UserAdmin
:docker-compose -f local.yml run --rm django python manage.py createsuperuser
django_1 | Request: <Context: {'id': '15dab4e4-2cca-4b65-8f75-2b4c40145e78', 'retries': 0, 'is_eager': True, 'logfile': None, 'loglevel': 0, 'hostname': '924647935b2f', 'callbacks': None, 'errbacks': None, 'headers': None, 'delivery_info': {'is_eager': True}, 'args': (), 'called_directly': False, 'kwargs': {}}>
I added a
sleep(10)
withindebug_task
to verify it was within the http request/response cycle and the browser hangs for 10 seconds then continues on.The text was updated successfully, but these errors were encountered: