Exemple #1
0
    def test_task_registered(self):
        """Test that @action decorator properly registers the
        task with the current app."""
        @action(name='i_should_be_registered')
        def test_task_should_be_reg(self):
            return

        from celery._state import get_current_app
        assert 'i_should_be_registered' in get_current_app().tasks
Exemple #2
0
    def test_task_no_kwargs(self):
        """Test that @action decorator works w/o kwargs."""
        #with using_test_app() as app:

        @action
        def test_no_kwargs_task(self, context):
            return 42

        from celery._state import get_current_app
        assert "{}.test_no_kwargs_task".format(__name__) in get_current_app().tasks
Exemple #3
0
    def setUp(self):
        self.app = get_current_app()

        self.old_broker_host = self.app.conf.BROKER_HOST or ''

        # Modifying the broken host name simulates the task broker being
        # 'unresponsive'
        # We need to make this modification in 3 places because of version
        # backwards compatibility
        self._set_broker_host('amqp://')
        self.app.conf['CELERY_TASK_PUBLISH_RETRY'] = False

        self.app._pool = None
        # Deleting the cache AMQP class so that it gets recreated with the new
        # BROKER_URL
        del self.app.amqp

        self.task = ParrotTask
Exemple #4
0
def setup_default_app(app, use_trap=False):
    """Setup default app for testing.

    Ensures state is clean after the test returns.
    """
    prev_current_app = _state.get_current_app()
    prev_default_app = _state.default_app
    prev_finalizers = set(_state._on_app_finalizers)
    prev_apps = weakref.WeakSet(_state._apps)

    if use_trap:
        with set_trap(app):
            yield
    else:
        yield

    _state.set_default_app(prev_default_app)
    _state._tls.current_app = prev_current_app
    if app is not prev_current_app:
        app.close()
    _state._on_app_finalizers = prev_finalizers
    _state._apps = prev_apps
Exemple #5
0
def setup_default_app(app, use_trap=False):
    """Setup default app for testing.

    Ensures state is clean after the test returns.
    """
    prev_current_app = _state.get_current_app()
    prev_default_app = _state.default_app
    prev_finalizers = set(_state._on_app_finalizers)
    prev_apps = weakref.WeakSet(_state._apps)

    if use_trap:
        with set_trap(app):
            yield
    else:
        yield

    _state.set_default_app(prev_default_app)
    _state._tls.current_app = prev_current_app
    if app is not prev_current_app:
        app.close()
    _state._on_app_finalizers = prev_finalizers
    _state._apps = prev_apps
Exemple #6
0
def _unpickle_task_v2(name, module=None):
    if module:
        import_module(module)
    return get_current_app().tasks[name]
Exemple #7
0
def _unpickle_task(name):
    return get_current_app().tasks[name]
Exemple #8
0
def _app_or_default(app=None):
    if app is None:
        return _state.get_current_app()
    return app
 def task_by_cons():
     app = _state.get_current_app()
     return app.tasks[
         name or app.gen_task_name(fun.__name__, fun.__module__)
     ]
Exemple #10
0
 def _get_default_app(self, *args, **kwargs):
     from celery._state import get_current_app
     return get_current_app()  # omit proxy
Exemple #11
0
 def _get_default_app(self, *args, **kwargs):
     from celery._state import get_current_app
     return get_current_app()  # omit proxy
Exemple #12
0
 def task_by_cons():
     app = _state.get_current_app()
     return app.tasks[
         name or app.gen_task_name(fun.__name__, fun.__module__)]
Exemple #13
0
 def test_get_default_app(self):
     self.patch('celery._state.get_current_app')
     cmd = MockCommand(app=self.app)
     from celery._state import get_current_app
     self.assertIs(cmd._get_default_app(), get_current_app())
Exemple #14
0
 def test_get_default_app(self, app, patching):
     patching('celery._state.get_current_app')
     cmd = MockCommand(app=app)
     from celery._state import get_current_app
     assert cmd._get_default_app() is get_current_app()
Exemple #15
0
 def app(self):
     """Instantiate the app if it wasn't already and return it. This lazy
     approach gives opportunity for further initializations before the app
     is imported."""
     return self._app_factory() or get_current_app()
Exemple #16
0
def _app_or_default(app=None):
    if app is None:
        return _state.get_current_app()
    return app
Exemple #17
0
def bugreport(app=None):
    """Return information useful in bug reports."""
    return (app or _state.get_current_app()).bugreport()
Exemple #18
0
 def test_get_default_app(self, app, patching):
     patching('celery._state.get_current_app')
     cmd = MockCommand(app=app)
     from celery._state import get_current_app
     assert cmd._get_default_app() is get_current_app()
Exemple #19
0
def _unpickle_appattr(reverse_name, args):
    """Given an attribute name and a list of args, gets
    the attribute from the current app and calls it."""
    return get_current_app()._rgetattr(reverse_name)(*args)
Exemple #20
0
from celery._state import get_current_app

app = get_current_app()


@app.task()
def add(x, y):
    print(x + y)
Exemple #21
0
def _unpickle_appattr(reverse_name, args):
    """Given an attribute name and a list of args, gets
    the attribute from the current app and calls it."""
    return get_current_app()._rgetattr(reverse_name)(*args)
Exemple #22
0
 def __init__(self, app, no_color, workdir, quiet=False):
     """Initialize the CLI context."""
     self.app = app or get_current_app()
     self.no_color = no_color
     self.quiet = quiet
     self.workdir = workdir
Exemple #23
0
 def test_get_default_app(self):
     self.patch('celery._state.get_current_app')
     cmd = MockCommand(app=self.app)
     from celery._state import get_current_app
     self.assertIs(cmd._get_default_app(), get_current_app())
def bugreport(app=None):
    """Return information useful in bug reports."""
    return (app or _state.get_current_app()).bugreport()