mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-13 05:06:58 +03:00
added optional celery support out of the box
This commit is contained in:
parent
b498bb4245
commit
eadd3e77f8
|
@ -47,6 +47,7 @@ Harry Percival / @hjwp
|
||||||
Cullen Rhodes / @c-rhodes
|
Cullen Rhodes / @c-rhodes
|
||||||
Audrey Roy Greenfeld / @audreyr (and creator/maintainer of cookiecutter) *
|
Audrey Roy Greenfeld / @audreyr (and creator/maintainer of cookiecutter) *
|
||||||
Burhan Khalid / @burhan
|
Burhan Khalid / @burhan
|
||||||
|
Jannis Gebauer / @got_nil
|
||||||
|
|
||||||
* Possesses commit rights
|
* Possesses commit rights
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ Features
|
||||||
* Basic e-mail configurations for send emails via Mailgun_
|
* Basic e-mail configurations for send emails via Mailgun_
|
||||||
* Media storage using Amazon S3
|
* Media storage using Amazon S3
|
||||||
* Serve static files from Amazon S3 or Whitenoise_ (optional)
|
* Serve static files from Amazon S3 or Whitenoise_ (optional)
|
||||||
|
* Pre configured Celery_ (optional)
|
||||||
|
|
||||||
.. _Bootstrap: https://github.com/twbs/bootstrap
|
.. _Bootstrap: https://github.com/twbs/bootstrap
|
||||||
.. _AngularJS: https://github.com/angular/angular.js
|
.. _AngularJS: https://github.com/angular/angular.js
|
||||||
|
@ -37,6 +38,7 @@ Features
|
||||||
.. _Procfile: https://devcenter.heroku.com/articles/procfile
|
.. _Procfile: https://devcenter.heroku.com/articles/procfile
|
||||||
.. _Mailgun: https://mailgun.com/
|
.. _Mailgun: https://mailgun.com/
|
||||||
.. _Whitenoise: https://whitenoise.readthedocs.org/
|
.. _Whitenoise: https://whitenoise.readthedocs.org/
|
||||||
|
.. _Celery: http://www.celeryproject.org/
|
||||||
|
|
||||||
|
|
||||||
Constraints
|
Constraints
|
||||||
|
|
|
@ -10,5 +10,6 @@
|
||||||
"now": "2015/01/13",
|
"now": "2015/01/13",
|
||||||
"year": "{{ cookiecutter.now[:4] }}",
|
"year": "{{ cookiecutter.now[:4] }}",
|
||||||
"use_whitenoise": "y",
|
"use_whitenoise": "y",
|
||||||
|
"use_celery": "n",
|
||||||
"windows": "n"
|
"windows": "n"
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,21 @@ To get live reloading to work you'll probably need to install an `appropriate br
|
||||||
|
|
||||||
.. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-
|
.. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-
|
||||||
|
|
||||||
|
{% if cookiecutter.use_celery == "y" %}
|
||||||
|
Celery
|
||||||
|
^^^^^^
|
||||||
|
This app comes with Celery.
|
||||||
|
|
||||||
|
To run a celery worker:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
cd {{cookiecutter.repo_name}}
|
||||||
|
celery -A {{cookiecutter.repo_name}} worker -l info
|
||||||
|
|
||||||
|
Please note: For Celerys import magic to work, it is important *where* the celery commands are run. If you are in the same folder with *manage.py*, you should be right.
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
It's time to write the code!!!
|
It's time to write the code!!!
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -256,4 +256,12 @@ LOGGING = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{% if cookiecutter.use_celery == "y" %}
|
||||||
|
########## CELERY
|
||||||
|
# if you are not using the django database broker (e.g. rabbitmq, redis, memcached), you can remove the next line.
|
||||||
|
INSTALLED_APPS += ('kombu.transport.django',)
|
||||||
|
BROKER_URL = env("CELERY_BROKER_URL", default='django://')
|
||||||
|
########## END CELERY
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# Your common stuff: Below this line define 3rd party library settings
|
# Your common stuff: Below this line define 3rd party library settings
|
||||||
|
|
|
@ -59,4 +59,11 @@ INSTALLED_APPS += ('django_extensions', )
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
|
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
|
||||||
|
|
||||||
|
{% if cookiecutter.celery_support == "y" %}
|
||||||
|
########## CELERY
|
||||||
|
# In development, all tasks will be executed locally by blocking until the task returns
|
||||||
|
CELERY_ALWAYS_EAGER = True
|
||||||
|
########## END CELERY
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# Your local stuff: Below this line define 3rd party library settings
|
# Your local stuff: Below this line define 3rd party library settings
|
||||||
|
|
|
@ -34,4 +34,8 @@ django-autoslug==1.8.0
|
||||||
# Time zones support
|
# Time zones support
|
||||||
pytz==2015.4
|
pytz==2015.4
|
||||||
|
|
||||||
|
{% if cookiecutter.use_celery == "y" %}
|
||||||
|
celery==3.1.18
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# Your custom requirements go here
|
# Your custom requirements go here
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
{% if cookiecutter.use_celery == "y" %}
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from {{cookiecutter.repo_name}}.celery import app as celery_app
|
||||||
|
{% endif %}
|
||||||
__version__ = '{{ cookiecutter.version }}'
|
__version__ = '{{ cookiecutter.version }}'
|
||||||
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
|
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{% if cookiecutter.use_celery == "y" %}
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from celery import Celery
|
||||||
|
|
||||||
|
# set the default Django settings module for the 'celery' program.
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
app = Celery('{{cookiecutter.repo_name}}')
|
||||||
|
|
||||||
|
# Using a string here means the worker will not have to
|
||||||
|
# pickle the object when using Windows.
|
||||||
|
app.config_from_object('django.conf:settings')
|
||||||
|
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def debug_task(self):
|
||||||
|
print('Request: {0!r}'.format(self.request))
|
||||||
|
{% else %}
|
||||||
|
# use this as a starting point for your project with celery.
|
||||||
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user