Skip to content

Commit

Permalink
* Add celery configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Jun 29, 2018
1 parent 0c08607 commit b7105ce
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions django_kala/django_kala/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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', 'django_kala.settings')

from django.conf import settings # noqa

app = Celery('django_kala')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
43 changes: 43 additions & 0 deletions django_kala/django_kala/settings/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .functions import get_env_variable

# Celery Configuration
DEPLOYMENT_ENVIRONMENT = get_env_variable('DEPLOYMENT_ENVIRONMENT')
if DEPLOYMENT_ENVIRONMENT == 'production':
# If we are in production, use SQS
AWS_REGION = get_env_variable('AWS_REGION', default='us-west-2')
CELERY_BROKER_URL = 'sqs://@'
CELERY_BROKER_TRANSPORT_OPTIONS = {'region': AWS_REGION}
CELERY_SEND_TASK_ERROR_EMAILS = True

# The global default rate limit for tasks. The default is no rate limit.
# http://docs.celeryproject.org/en/latest/configuration.html#celery-default-rate-limit
CELERY_DEFAULT_RATE_LIMIT = '1/s'

CELERY_ACCEPT_CONTENT = ['pickle']
CELERY_TASK_SERIALIZER = 'pickle'

# How many messages to prefetch at a time; default is 4
# http://docs.celeryproject.org/en/latest/configuration.html#celeryd-prefetch-multiplier
CELERYD_PREFETCH_MULTIPLIER = 1

# Task messages will be retried in the case of connection loss or other
# connection errors
# http://docs.celeryproject.org/en/latest/configuration.html#celery-task-publish-retry
CELERY_TASK_PUBLISH_RETRY = True

# Defines the default policy when retrying publishing a task message in the
# case of connection loss or other connection errors
# http://docs.celeryproject.org/en/latest/configuration.html#celery-task-publish-retry-policy
CELERY_TASK_PUBLISH_RETRY_POLICY = {
'max_retries': 3,
}

# Disabling rate limits altogether is recommended if you don't have any tasks
# using them.
# http://docs.celeryproject.org/en/latest/userguide/tasks.html#disable-rate-limits-if-they-re-not-used
CELERY_DISABLE_RATE_LIMITS = True

# Late ack means the task messages will be acknowledged after the task has been
# executed, not just before, which is the default behavior.
# http://docs.celeryproject.org/en/latest/configuration.html#celery-acks-late
CELERY_ACKS_LATE = True

0 comments on commit b7105ce

Please sign in to comment.