Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from mkiwala/celery-commom-config
Browse files Browse the repository at this point in the history
Celery commom config
  • Loading branch information
mkiwala committed Nov 18, 2015
2 parents aab4bbb + 35fda72 commit d692d45
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ptero_common/celery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

_CONFIGURATION_NAMES = {
'CELERY_BROKER_URL': 'BROKER_URL',
'CELERY_BROKER_HEARTBEAT': 'BROKER_HEARTBEAT',
'CELERY_BROKER_HEARTBEAT_CHECKRATE': 'BROKER_HEARTBEAT_CHECKRATE',
}


Expand Down Expand Up @@ -33,6 +35,8 @@ def _bool_formatter(value):
_FORMATTERS = {
'CELERY_ACCEPT_CONTENT': _list_formatter,
'CELERY_ACKS_LATE': _bool_formatter,
'BROKER_HEARTBEAT': float,
'BROKER_HEARTBEAT_CHECKRATE': float,
'CELERY_PREFETCH_MULTIPLIER': int,
'CELERY_TRACK_STARTED': _bool_formatter,
}
Expand All @@ -42,7 +46,7 @@ def _get_formatter(config_name):
return _FORMATTERS.get(config_name, _default_formatter)


def get_config_from_env(service_name):
def _get_config_from_env(service_name):
result = {}
for env_var_name, env_var_value in os.environ.iteritems():
if re.match('PTERO_%s_CELERY' % service_name, env_var_name):
Expand All @@ -56,3 +60,15 @@ def get_config_from_env(service_name):
config_name, str(config_value), env_var_name, env_var_value)

return result


def get_celery_config(service_name):
config = _get_config_from_env(service_name)
config.update({
'BROKER_TRANSPORT_OPTIONS': {'confirm_publish': True},
'CELERY_ACCEPT_CONTENT': ['json'],
'CELERY_ACKS_LATE': True,
'CELERY_RESULT_SERIALIZER': 'json',
'CELERY_TASK_SERIALIZER': 'json',
})
return config

0 comments on commit d692d45

Please sign in to comment.