mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-04-12 12:54:20 +03:00
refactored to load celery from an AppConfig
This commit is contained in:
parent
073666e09c
commit
9bfca28f6f
|
@ -257,6 +257,7 @@ LOGGING = {
|
|||
}
|
||||
{% if cookiecutter.use_celery == "y" %}
|
||||
########## CELERY
|
||||
INSTALLED_APPS += ('{{cookiecutter.repo_name}}.taskman.celery.CeleryConfig',)
|
||||
# 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://')
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
# -*- 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_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
{% 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 %}
|
|
@ -0,0 +1,32 @@
|
|||
{% if cookiecutter.use_celery == "y" %}
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
from celery import Celery
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
# set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
||||
|
||||
|
||||
app = Celery('{{cookiecutter.repo_name}}')
|
||||
|
||||
|
||||
class CeleryConfig(AppConfig):
|
||||
name = '{{cookiecutter.repo_name}}.taskman'
|
||||
verbose_name = 'Celery Config'
|
||||
|
||||
def ready(self):
|
||||
# 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, force=True)
|
||||
|
||||
|
||||
@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