| 46 | True |
| 47 | """ |
| 48 | def create_shared_task(**options): |
| 49 | |
| 50 | def __inner(fun): |
| 51 | if type(fun) is Proxy: |
| 52 | raise TypeError( |
| 53 | '@shared_task was applied more than once to the same ' |
| 54 | 'function. Remove the extra @shared_task decorator.' |
| 55 | ) |
| 56 | name = options.get('name') |
| 57 | # Set as shared task so that unfinalized apps, |
| 58 | # and future apps will register a copy of this task. |
| 59 | _state.connect_on_app_finalize( |
| 60 | lambda app: app._task_from_fun(fun, **options) |
| 61 | ) |
| 62 | |
| 63 | # Force all finalized apps to take this task as well. |
| 64 | for app in _state._get_active_apps(): |
| 65 | if app.finalized: |
| 66 | with app._finalize_mutex: |
| 67 | app._task_from_fun(fun, **options) |
| 68 | |
| 69 | # Return a proxy that always gets the task from the current |
| 70 | # apps task registry. |
| 71 | def task_by_cons(): |
| 72 | app = _state.get_current_app() |
| 73 | return app.tasks[ |
| 74 | name or app.gen_task_name(fun.__name__, fun.__module__) |
| 75 | ] |
| 76 | return Proxy(task_by_cons) |
| 77 | return __inner |
| 78 | |
| 79 | if len(args) == 1 and callable(args[0]): |
| 80 | return create_shared_task(**kwargs)(args[0]) |