forked from celery/django-celery-results
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[celery#305]: Added a default callable to
get_callback_function
`get_callback_function()` gets a default callback as an arg returning explicitely an empty dict. `get_callback_function()` raises an `ImproperlyConfigured` exception when the callback is not callable. --- Resolves celery#305 Fixes celery#314
- Loading branch information
1 parent
696d9d4
commit 4eefed9
Showing
2 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
def get_callback_function(settings_name, default=None): | ||
"""Return the callback function for the given settings name.""" | ||
|
||
callback = getattr(settings, settings_name, None) | ||
if callback is None: | ||
if not callback: | ||
return default | ||
|
||
if callable(callback): | ||
return callback | ||
if not callable(callback): | ||
raise ImproperlyConfigured(f"{settings_name} must be callable.") | ||
|
||
return callback | ||
|
||
extend_task_props_callback = get_callback_function( | ||
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK" | ||
"CELERY_RESULTS_EXTEND_TASK_PROPS_CALLBACK", dict | ||
) |