Last active
August 29, 2015 14:08
-
-
Save alb3rto269/add08acc212af9f1ac83 to your computer and use it in GitHub Desktop.
celery 3.1 + django-configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/mysite | |
| app1/ | |
| models.py | |
| tasks.py | |
| app2/ | |
| models.py | |
| tasks.py | |
| config/ | |
| local.py | |
| development.py | |
| production.py | |
| settings.py | |
| celery.py | |
| manage.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
import os | |
from celery import Celery | |
from django.conf import settings | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | |
os.environ.setdefault('DJANGO_CONFIGURATION', 'Local') | |
from configurations import importer | |
importer.install() | |
app = Celery('mysite') | |
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from configurations import Configuration | |
class Local(Configuration): | |
... | |
INSTALLED_APPS = ( | |
... | |
'app1', | |
'app2' | |
... | |
) | |
... | |
# CELERY CONFIGURATION | |
CELERY_REDIRECT_STDOUTS_LEVEL = 'DEBUG' | |
BROKER_URL = 'redis://localhost:6379/0' | |
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0' | |
# END CELERY CONFIGURATION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from .local import Local | |
from .development import ev | |
from .production import Prod | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from config.celery import app as celery_app | |
@celery_app.task | |
def hello_world(): | |
print('Hello World') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To start celery workers run from the django root directory (
config
is the path where livescelery.py
)To run tasks: