'Decorator to create a task class out of any callable.
Examples:
.. code-block:: python
@app.task
def refresh_feed(url):
store_feed(feedparser.parse(url))
with setting extra options:
.. code-block:: python
@app.task(exchange=\'feeds\')
def refresh_feed(url):
return store_feed(feedparser.parse(url))
Note:
App Binding: For custom apps the task decorator will return
a proxy object, so that the act of creating the task is not
performed until the task is used or the task registry is accessed.
If you\'re depending on binding to be deferred, then you must
not access any attributes on the returned object until the
application is fully set up (finalized).'

def task(self, *args, **opts):

    if (USING_EXECV and opts.get(u'lazy', True)):
        from . import shared_task
        return shared_task(lazy=False, *args, **opts)
    def inner_create_task_cls(shared=True, filter=None, lazy=True, **opts):
        _filt = filter
        def _create_task_cls(fun):
            if shared:
                def cons(app):
                    return app._task_from_fun(fun, **opts)
                cons.__name__ = fun.__name__
                connect_on_app_finalize(cons)
            if ((not lazy) or self.finalized):
                ret = self._task_from_fun(fun, **opts)
            else:
                ret = PromiseProxy(self._task_from_fun, (fun,), opts, __doc__=fun.__doc__)
                self._pending.append(ret)
            if _filt:
                return _filt(ret)
            return ret
        return _create_task_cls
    if (len(args) == 1):
        if callable(args[0]):
            return inner_create_task_cls(**opts)(*args)
        raise TypeError(u'argument    1    to    @task()    must    be    a    callable')
    if args:
        raise TypeError(u'@task()    takes    exactly    1    argument    ({0}    given)'.format(sum([len(args), len(opts)])))
    return inner_create_task_cls(**opts)
