瀏覽代碼

Removes deprecated TaskSet and TaskSetResult, and the .task.sets module

Ask Solem 9 年之前
父節點
當前提交
e3cab12540
共有 6 個文件被更改,包括 2 次插入403 次删除
  1. 0 10
      celery/app/base.py
  2. 1 31
      celery/result.py
  3. 1 3
      celery/task/__init__.py
  4. 0 88
      celery/task/sets.py
  5. 0 245
      celery/tests/compat_modules/test_sets.py
  6. 0 26
      celery/tests/tasks/test_result.py

+ 0 - 10
celery/app/base.py

@@ -996,16 +996,6 @@ class Celery(object):
         """
         return self.subclass_with_self('celery.result:GroupResult')
 
-    @cached_property
-    def TaskSet(self):  # XXX compat
-        """Deprecated! Please use :class:`celery.group` instead."""
-        return self.subclass_with_self('celery.task.sets:TaskSet')
-
-    @cached_property
-    def TaskSetResult(self):  # XXX compat
-        """Deprecated! Please use :attr:`GroupResult` instead."""
-        return self.subclass_with_self('celery.result:TaskSetResult')
-
     @property
     def pool(self):
         """Broker connection pool: :class:`~@pool`.

+ 1 - 31
celery/result.py

@@ -756,8 +756,7 @@ class ResultSet(ResultBase):
 class GroupResult(ResultSet):
     """Like :class:`ResultSet`, but with an associated id.
 
-    This type is returned by :class:`~celery.group`, and the
-    deprecated TaskSet, meth:`~celery.task.TaskSet.apply_async` method.
+    This type is returned by :class:`~celery.group`.
 
     It enables inspection of the tasks state and return values as
     a single entity.
@@ -826,35 +825,6 @@ class GroupResult(ResultSet):
         ).restore_group(id)
 
 
-class TaskSetResult(GroupResult):
-    """Deprecated version of :class:`GroupResult`"""
-
-    def __init__(self, taskset_id, results=None, **kwargs):
-        # XXX supports the taskset_id kwarg.
-        # XXX previously the "results" arg was named "subtasks".
-        if 'subtasks' in kwargs:
-            results = kwargs['subtasks']
-        GroupResult.__init__(self, taskset_id, results, **kwargs)
-
-    def itersubtasks(self):
-        """Deprecated.   Use ``iter(self.results)`` instead."""
-        return iter(self.results)
-
-    @property
-    def total(self):
-        """Deprecated: Use ``len(r)``."""
-        return len(self)
-
-    @property
-    def taskset_id(self):
-        """compat alias to :attr:`self.id`"""
-        return self.id
-
-    @taskset_id.setter  # noqa
-    def taskset_id(self, id):
-        self.id = id
-
-
 class EagerResult(AsyncResult):
     """Result that we know has already been executed."""
     task_name = None

+ 1 - 3
celery/task/__init__.py

@@ -17,7 +17,7 @@ from celery.local import Proxy
 
 __all__ = [
     'BaseTask', 'Task', 'PeriodicTask', 'task', 'periodic_task',
-    'group', 'chord', 'subtask', 'TaskSet',
+    'group', 'chord', 'subtask',
 ]
 
 
@@ -29,7 +29,6 @@ if STATICA_HACK:  # pragma: no cover
     # they contain.
     from celery.canvas import group, chord, subtask
     from .base import BaseTask, Task, PeriodicTask, task, periodic_task
-    from .sets import TaskSet
 
 
 class module(LazyModule):
@@ -44,7 +43,6 @@ old_module, new_module = recreate_module(  # pragma: no cover
         'celery.task.base': ['BaseTask', 'Task', 'PeriodicTask',
                              'task', 'periodic_task'],
         'celery.canvas': ['group', 'chord', 'subtask'],
-        'celery.task.sets': ['TaskSet'],
     },
     base=module,
     __package__='celery.task',

+ 0 - 88
celery/task/sets.py

@@ -1,88 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    celery.task.sets
-    ~~~~~~~~~~~~~~~~
-
-    Old ``group`` implementation, this module should
-    not be used anymore use :func:`celery.group` instead.
-
-"""
-from __future__ import absolute_import
-
-from celery._state import get_current_worker_task
-from celery.app import app_or_default
-from celery.canvas import maybe_signature  # noqa
-from celery.utils import uuid, warn_deprecated
-
-from celery.canvas import subtask   # noqa
-
-warn_deprecated(
-    'celery.task.sets and TaskSet', removal='4.0',
-    alternative="""\
-Please use "group" instead (see the Canvas section in the userguide)\
-""")
-
-
-class TaskSet(list):
-    """A task containing several subtasks, making it possible
-    to track how many, or when all of the tasks have been completed.
-
-    :param tasks: A list of :class:`subtask` instances.
-
-    Example::
-
-        >>> from myproj.tasks import refresh_feed
-
-        >>> urls = ('http://cnn.com/rss', 'http://bbc.co.uk/rss')
-        >>> s = TaskSet(refresh_feed.s(url) for url in urls)
-        >>> taskset_result = s.apply_async()
-        >>> list_of_return_values = taskset_result.join()  # *expensive*
-
-    """
-    app = None
-
-    def __init__(self, tasks=None, app=None, Publisher=None):
-        self.app = app_or_default(app or self.app)
-        super(TaskSet, self).__init__(
-            maybe_signature(t, app=self.app) for t in tasks or []
-        )
-        self.Publisher = Publisher or self.app.amqp.Producer
-        self.total = len(self)  # XXX compat
-
-    def apply_async(self, connection=None, publisher=None, taskset_id=None):
-        """Apply TaskSet."""
-        app = self.app
-
-        if app.conf.task_always_eager:
-            return self.apply(taskset_id=taskset_id)
-
-        with app.connection_or_acquire(connection) as conn:
-            setid = taskset_id or uuid()
-            pub = publisher or self.Publisher(conn)
-            results = self._async_results(setid, pub)
-
-            result = app.TaskSetResult(setid, results)
-            parent = get_current_worker_task()
-            if parent:
-                parent.add_trail(result)
-            return result
-
-    def _async_results(self, taskset_id, publisher):
-        return [task.apply_async(taskset_id=taskset_id, publisher=publisher)
-                for task in self]
-
-    def apply(self, taskset_id=None):
-        """Applies the TaskSet locally by blocking until all tasks return."""
-        setid = taskset_id or uuid()
-        return self.app.TaskSetResult(setid, self._sync_results(setid))
-
-    def _sync_results(self, taskset_id):
-        return [task.apply(taskset_id=taskset_id) for task in self]
-
-    @property
-    def tasks(self):
-        return self
-
-    @tasks.setter  # noqa
-    def tasks(self, tasks):
-        self[:] = tasks

+ 0 - 245
celery/tests/compat_modules/test_sets.py

@@ -1,245 +0,0 @@
-from __future__ import absolute_import
-
-import warnings
-
-from kombu.utils import json
-
-from celery import uuid
-from celery.result import TaskSetResult
-from celery.task import Task
-from celery.canvas import Signature
-
-from celery.tests.tasks.test_result import make_mock_group
-from celery.tests.case import AppCase, Mock, patch
-
-
-class SetsCase(AppCase):
-
-    def setup(self):
-        with warnings.catch_warnings(record=True):
-            from celery.task import sets
-            self.sets = sets
-            self.subtask = sets.subtask
-            self.TaskSet = sets.TaskSet
-
-        class MockTask(Task):
-            app = self.app
-            name = 'tasks.add'
-
-            def run(self, x, y, **kwargs):
-                return x + y
-
-            @classmethod
-            def apply_async(cls, args, kwargs, **options):
-                return (args, kwargs, options)
-
-            @classmethod
-            def apply(cls, args, kwargs, **options):
-                return (args, kwargs, options)
-        self.MockTask = MockTask
-
-
-class test_TaskSetResult(AppCase):
-
-    def setup(self):
-        self.size = 10
-        self.ts = TaskSetResult(uuid(), make_mock_group(self.app, self.size))
-
-    def test_total(self):
-        self.assertEqual(self.ts.total, self.size)
-
-    def test_compat_properties(self):
-        self.assertEqual(self.ts.taskset_id, self.ts.id)
-        self.ts.taskset_id = 'foo'
-        self.assertEqual(self.ts.taskset_id, 'foo')
-
-    def test_compat_subtasks_kwarg(self):
-        x = TaskSetResult(uuid(), subtasks=[1, 2, 3])
-        self.assertEqual(x.results, [1, 2, 3])
-
-    def test_itersubtasks(self):
-        it = self.ts.itersubtasks()
-
-        for i, t in enumerate(it):
-            self.assertEqual(t.get(), i)
-
-
-class test_App(AppCase):
-
-    def test_TaskSet(self):
-        with warnings.catch_warnings(record=True):
-            ts = self.app.TaskSet()
-            self.assertListEqual(ts.tasks, [])
-            self.assertIs(ts.app, self.app)
-
-
-class test_subtask(SetsCase):
-
-    def test_behaves_like_type(self):
-        s = self.subtask('tasks.add', (2, 2), {'cache': True},
-                         {'routing_key': 'CPU-bound'})
-        self.assertDictEqual(self.subtask(s), s)
-
-    def test_task_argument_can_be_task_cls(self):
-        s = self.subtask(self.MockTask, (2, 2))
-        self.assertEqual(s.task, self.MockTask.name)
-
-    def test_apply_async(self):
-        s = self.MockTask.subtask(
-            (2, 2), {'cache': True}, {'routing_key': 'CPU-bound'},
-        )
-        args, kwargs, options = s.apply_async()
-        self.assertTupleEqual(args, (2, 2))
-        self.assertDictEqual(kwargs, {'cache': True})
-        self.assertDictEqual(options, {'routing_key': 'CPU-bound'})
-
-    def test_delay_argmerge(self):
-        s = self.MockTask.subtask(
-            (2,), {'cache': True}, {'routing_key': 'CPU-bound'},
-        )
-        args, kwargs, options = s.delay(10, cache=False, other='foo')
-        self.assertTupleEqual(args, (10, 2))
-        self.assertDictEqual(kwargs, {'cache': False, 'other': 'foo'})
-        self.assertDictEqual(options, {'routing_key': 'CPU-bound'})
-
-    def test_apply_async_argmerge(self):
-        s = self.MockTask.subtask(
-            (2,), {'cache': True}, {'routing_key': 'CPU-bound'},
-        )
-        args, kwargs, options = s.apply_async((10,),
-                                              {'cache': False, 'other': 'foo'},
-                                              routing_key='IO-bound',
-                                              exchange='fast')
-
-        self.assertTupleEqual(args, (10, 2))
-        self.assertDictEqual(kwargs, {'cache': False, 'other': 'foo'})
-        self.assertDictEqual(options, {'routing_key': 'IO-bound',
-                                       'exchange': 'fast'})
-
-    def test_apply_argmerge(self):
-        s = self.MockTask.subtask(
-            (2,), {'cache': True}, {'routing_key': 'CPU-bound'},
-        )
-        args, kwargs, options = s.apply((10,),
-                                        {'cache': False, 'other': 'foo'},
-                                        routing_key='IO-bound',
-                                        exchange='fast')
-
-        self.assertTupleEqual(args, (10, 2))
-        self.assertDictEqual(kwargs, {'cache': False, 'other': 'foo'})
-        self.assertDictEqual(
-            options, {'routing_key': 'IO-bound', 'exchange': 'fast'},
-        )
-
-    def test_is_JSON_serializable(self):
-        s = self.MockTask.subtask(
-            (2,), {'cache': True}, {'routing_key': 'CPU-bound'},
-        )
-        # tuples are not preserved, but this doesn't matter.
-        s.args = list(s.args)
-        self.assertEqual(s, self.subtask(json.loads(json.dumps(s))))
-
-    def test_repr(self):
-        s = self.MockTask.subtask((2,), {'cache': True})
-        self.assertIn('2', repr(s))
-        self.assertIn('cache=True', repr(s))
-
-    def test_reduce(self):
-        s = self.MockTask.subtask((2,), {'cache': True})
-        cls, args = s.__reduce__()
-        self.assertDictEqual(dict(cls(*args)), dict(s))
-
-
-class test_TaskSet(SetsCase):
-
-    def test_task_arg_can_be_iterable__compat(self):
-        ts = self.TaskSet([self.MockTask.subtask((i, i))
-                           for i in (2, 4, 8)], app=self.app)
-        self.assertEqual(len(ts), 3)
-
-    def test_respects_ALWAYS_EAGER(self):
-        app = self.app
-
-        class MockTaskSet(self.TaskSet):
-            applied = 0
-
-            def apply(self, *args, **kwargs):
-                self.applied += 1
-
-        ts = MockTaskSet(
-            [self.MockTask.subtask((i, i)) for i in (2, 4, 8)],
-            app=self.app,
-        )
-        app.conf.task_always_eager = True
-        ts.apply_async()
-        self.assertEqual(ts.applied, 1)
-        app.conf.task_always_eager = False
-
-        with patch('celery.task.sets.get_current_worker_task') as gwt:
-            parent = gwt.return_value = Mock()
-            ts.apply_async()
-            self.assertTrue(parent.add_trail.called)
-
-    def test_apply_async(self):
-        applied = [0]
-
-        class mocksubtask(Signature):
-
-            def apply_async(self, *args, **kwargs):
-                applied[0] += 1
-
-        ts = self.TaskSet([mocksubtask(self.MockTask, (i, i))
-                           for i in (2, 4, 8)], app=self.app)
-        ts.apply_async()
-        self.assertEqual(applied[0], 3)
-
-        class Publisher(object):
-
-            def send(self, *args, **kwargs):
-                pass
-
-        ts.apply_async(publisher=Publisher())
-
-        # setting current_task
-
-        @self.app.task(shared=False)
-        def xyz():
-            pass
-
-        from celery._state import _task_stack
-        xyz.push_request()
-        _task_stack.push(xyz)
-        try:
-            ts.apply_async(publisher=Publisher())
-        finally:
-            _task_stack.pop()
-            xyz.pop_request()
-
-    def test_apply(self):
-
-        applied = [0]
-
-        class mocksubtask(Signature):
-
-            def apply(self, *args, **kwargs):
-                applied[0] += 1
-
-        ts = self.TaskSet([mocksubtask(self.MockTask, (i, i))
-                           for i in (2, 4, 8)], app=self.app)
-        ts.apply()
-        self.assertEqual(applied[0], 3)
-
-    def test_set_app(self):
-        ts = self.TaskSet([], app=self.app)
-        ts.app = 42
-        self.assertEqual(ts.app, 42)
-
-    def test_set_tasks(self):
-        ts = self.TaskSet([], app=self.app)
-        ts.tasks = [1, 2, 3]
-        self.assertEqual(ts, [1, 2, 3])
-
-    def test_set_Publisher(self):
-        ts = self.TaskSet([], app=self.app)
-        ts.Publisher = 42
-        self.assertEqual(ts.Publisher, 42)

+ 0 - 26
celery/tests/tasks/test_result.py

@@ -8,7 +8,6 @@ from celery.five import range
 from celery.result import (
     AsyncResult,
     EagerResult,
-    TaskSetResult,
     result_from_tuple,
 )
 from celery.utils import uuid
@@ -409,31 +408,6 @@ class SimpleBackend(object):
                     for i, id in enumerate(self.ids))
 
 
-class test_TaskSetResult(AppCase):
-
-    def setup(self):
-        self.size = 10
-        self.ts = TaskSetResult(uuid(), make_mock_group(self.app, self.size))
-
-    def test_total(self):
-        self.assertEqual(self.ts.total, self.size)
-
-    def test_compat_properties(self):
-        self.assertEqual(self.ts.taskset_id, self.ts.id)
-        self.ts.taskset_id = 'foo'
-        self.assertEqual(self.ts.taskset_id, 'foo')
-
-    def test_compat_subtasks_kwarg(self):
-        x = TaskSetResult(uuid(), subtasks=[1, 2, 3])
-        self.assertEqual(x.results, [1, 2, 3])
-
-    def test_itersubtasks(self):
-        it = self.ts.itersubtasks()
-
-        for i, t in enumerate(it):
-            self.assertEqual(t.get(), i)
-
-
 class test_GroupResult(AppCase):
 
     def setup(self):