From aea5c807f6c3d123b5d8dbe7e0ceaa2791abcbee Mon Sep 17 00:00:00 2001 From: keithjeb Date: Sat, 2 Mar 2019 14:51:30 +0100 Subject: [PATCH] Change eager celery setting in local Docker (#1945) [//]: # (Thank you for helping us out: your efforts mean great deal to the project and the community as a whole!) [//]: # (Before you proceed:) [//]: # (1. Make sure to add yourself to `CONTRIBUTORS.rst` through this PR provided you're contributing here for the first time) [//]: # (2. Don't forget to update the `docs/` presuming others would benefit from a concise description of whatever that you're proposing) ## Description [//]: # (What's it you're proposing?) Added a note around CELERY_TASK_ALWAYS_EAGER = True in docker config for local development. This causes tasks to be executed on the 'main' thread rather than by the workers. I understand why that might be desirable, but thought it worth calling out incase (like me) it makes people think something is broken. ## Rationale [//]: # (Why does the project need that?) Ease of use/troubleshooting ## Use case(s) / visualization(s) [//]: # ("Better to see something once than to hear about it a thousand times.") --- CONTRIBUTORS.rst | 2 ++ docs/developing-locally-docker.rst | 10 ++++++++++ docs/developing-locally.rst | 10 ++++++++++ {{cookiecutter.project_slug}}/config/settings/local.py | 2 ++ 4 files changed, 24 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index e6111cd15..0de1077e6 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -180,6 +180,7 @@ Listed in alphabetical order. Denis Bobrov `@delneg`_ Philipp Matthies `@canonnervio`_ Vadim Iskuchekov `@Egregors`_ @egregors + Keith Bailey `@keithjeb`_ ========================== ============================ ============== .. _@a7p: https://github.com/a7p @@ -297,6 +298,7 @@ Listed in alphabetical order. .. _@purplediane: https://github.com/purplediane .. _@umrashrf: https://github.com/umrashrf .. _@ahhda: https://github.com/ahhda +.. _@keithjeb: https://github.com/keithjeb Special Thanks ~~~~~~~~~~~~~~ diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 08b25f3bc..895140f9c 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -171,6 +171,16 @@ When developing locally you can go with MailHog_ for email testing provided ``us .. _Mailhog: https://github.com/mailhog/MailHog/ +.. _`CeleryTasks`: + +Celery tasks in local development +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +When not using docker Celery tasks are set to run in Eager mode, so that a full stack is not needed. When using docker the task +scheduler will be used by default. + +If you need tasks to be executed on the main thread during development set CELERY_TASK_ALWAYS_EAGER = True in config/settings/local.py. + +Possible uses could be for testing, or ease of profiling with DJDT. .. _`CeleryFlower`: diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 09c5db396..3434f68b6 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -118,6 +118,16 @@ In production, we have Mailgun_ configured to have your back! .. _Mailgun: https://www.mailgun.com/ +Celery +------ +If the project is configured to use Celery as a task scheduler then by default tasks are set to run on the main thread +when developing locally. If you have the appropriate setup on your local machine then set + +CELERY_TASK_ALWAYS_EAGER = False + +in /config/settings/local.py + + Sass Compilation & Live Reloading --------------------------------- diff --git a/{{cookiecutter.project_slug}}/config/settings/local.py b/{{cookiecutter.project_slug}}/config/settings/local.py index 741f324af..6667a2653 100644 --- a/{{cookiecutter.project_slug}}/config/settings/local.py +++ b/{{cookiecutter.project_slug}}/config/settings/local.py @@ -76,8 +76,10 @@ INSTALLED_APPS += ['django_extensions'] # noqa F405 # Celery # ------------------------------------------------------------------------------ +{% if cookiecutter.use_docker == 'n' -%} # http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-always-eager CELERY_TASK_ALWAYS_EAGER = True +{%- endif %} # http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-eager-propagates CELERY_TASK_EAGER_PROPAGATES = True