Browse Source

Removes celery.contrib.methods. Too many bugs to be usable

Ask Solem 10 years ago
parent
commit
4f43276c23

+ 0 - 126
celery/contrib/methods.py

@@ -1,126 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-celery.contrib.methods
-======================
-
-Task decorator that supports creating tasks out of methods.
-
-Examples
---------
-
-.. code-block:: python
-
-    from celery.contrib.methods import task
-
-    class X(object):
-
-        @task()
-        def add(self, x, y):
-                return x + y
-
-or with any task decorator:
-
-.. code-block:: python
-
-    from celery.contrib.methods import task_method
-
-    class X(object):
-
-        @app.task(filter=task_method)
-        def add(self, x, y):
-            return x + y
-
-.. note::
-
-    The task must use the new Task base class (:class:`celery.Task`),
-    and the old base class using classmethods (``celery.task.Task``,
-    ``celery.task.base.Task``).
-
-    This means that you have to use the task decorator from a Celery app
-    instance, and not the old-API:
-
-    .. code-block:: python
-
-
-        from celery import task       # BAD
-        from celery.task import task  # ALSO BAD
-
-        # GOOD:
-        app = Celery(...)
-
-        @app.task(filter=task_method)
-        def foo(self): pass
-
-        # ALSO GOOD:
-        from celery import current_app
-
-        @current_app.task(filter=task_method)
-        def foo(self): pass
-
-        # ALSO GOOD:
-        from celery import shared_task
-
-        @shared_task(filter=task_method)
-        def foo(self): pass
-
-Caveats
--------
-
-- Automatic naming won't be able to know what the class name is.
-
-    The name will still be module_name + task_name,
-    so two methods with the same name in the same module will collide
-    so that only one task can run:
-
-    .. code-block:: python
-
-        class A(object):
-
-            @task()
-            def add(self, x, y):
-                return x + y
-
-        class B(object):
-
-            @task()
-            def add(self, x, y):
-                return x + y
-
-    would have to be written as:
-
-    .. code-block:: python
-
-        class A(object):
-            @task(name='A.add')
-            def add(self, x, y):
-                return x + y
-
-        class B(object):
-            @task(name='B.add')
-            def add(self, x, y):
-                return x + y
-
-"""
-
-from __future__ import absolute_import
-
-from celery import current_app
-
-__all__ = ['task_method', 'task']
-
-
-class task_method(object):
-
-    def __init__(self, task, *args, **kwargs):
-        self.task = task
-
-    def __get__(self, obj, type=None):
-        if obj is None:
-            return self.task
-        task = self.task.__class__()
-        task.__self__ = obj
-        return task
-
-
-def task(*args, **kwargs):
-    return current_app.task(*args, **dict(kwargs, filter=task_method))

+ 0 - 34
celery/tests/contrib/test_methods.py

@@ -1,34 +0,0 @@
-from __future__ import absolute_import
-
-from celery.contrib.methods import task_method, task
-
-from celery.tests.case import AppCase, patch
-
-
-class test_task_method(AppCase):
-
-    def test_task_method(self):
-
-        class X(object):
-
-            def __init__(self):
-                self.state = 0
-
-            @self.app.task(shared=False, filter=task_method)
-            def add(self, x):
-                self.state += x
-
-        x = X()
-        x.add(2)
-        self.assertEqual(x.state, 2)
-        x.add(4)
-        self.assertEqual(x.state, 6)
-
-        self.assertTrue(X.add)
-        self.assertIs(x.add.__self__, x)
-
-    def test_task(self):
-        with patch('celery.contrib.methods.current_app') as curapp:
-            fun = object()
-            task(fun, x=1)
-            curapp.task.assert_called_with(fun, x=1, filter=task_method)

+ 0 - 5
docs/reference/celery.contrib.methods.rst

@@ -1,5 +0,0 @@
-.. currentmodule:: celery.contrib.methods
-
-.. automodule:: celery.contrib.methods
-    :members:
-    :undoc-members:

+ 0 - 1
docs/reference/index.rst

@@ -39,7 +39,6 @@
     celery.contrib.migrate
     celery.contrib.sphinx
     celery.contrib.rdb
-    celery.contrib.methods
     celery.events
     celery.events.state
     celery.beat