Skip to content

Commit

Permalink
fix celery config
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Sep 12, 2020
1 parent 9b457fc commit 032e3a8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/example/static/
/manage.py
/project
celerybeat-schedule

# Node
node_modules
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
extras_require={
'files': PYTHON_MAGIC_DEP,
'huey': 'huey == 2.3.0',
'celery': 'celery == 4.4.7'},
'celery': 'celery[redis] == 4.4.7'},
license='MIT License',
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
3 changes: 3 additions & 0 deletions spirit/extra/project_template/project_name/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# from .celery import app as celery_app
# __all__ = ('celery_app',)
5 changes: 3 additions & 2 deletions spirit/extra/project_template/project_name/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import os
from celery import Celery
from django.conf import settings

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.prod")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.dev")
app = Celery('{{ project_name }}')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
10 changes: 10 additions & 0 deletions spirit/extra/project_template/project_name/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@
'health_check_interval': 1,
}
}

CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERY_BEAT_SCHEDULE = {
'context': {
'task': 'spirit.core.tasks.full_search_index_update',
'schedule': 3600 * 24 # run once every 24hs
}
}
8 changes: 5 additions & 3 deletions spirit/extra/project_template/project_name/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@
# Celery is optional, Huey can be used instead
# https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
# https://docs.celeryproject.org/en/latest/userguide/configuration.html
CELERY_BROKER_URL = 'amqp://localhost'
CELERYBEAT_SCHEDULE = {
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERY_BEAT_SCHEDULE = {
'context': {
'task': 'spirit.core.tasks.full_search_index_update',
'schedule': 3600 * 24,
'schedule': 3600 * 24 # run once every 24hs
}
}

Expand Down

0 comments on commit 032e3a8

Please sign in to comment.