|
@@ -1,3 +1,5 @@
|
|
|
|
+import warnings
|
|
|
|
+
|
|
from UserList import UserList
|
|
from UserList import UserList
|
|
|
|
|
|
from celery import conf
|
|
from celery import conf
|
|
@@ -8,6 +10,28 @@ from celery.messaging import TaskPublisher
|
|
from celery.result import TaskSetResult
|
|
from celery.result import TaskSetResult
|
|
from celery.utils import gen_unique_id
|
|
from celery.utils import gen_unique_id
|
|
|
|
|
|
|
|
+TASKSET_DEPRECATION_TEXT = """\
|
|
|
|
+Using this invocation of TaskSet is deprecated and will be removed
|
|
|
|
+in Celery v2.4!
|
|
|
|
+
|
|
|
|
+TaskSets now supports multiple types of tasks, the API has to reflect
|
|
|
|
+this so the syntax has been changed to:
|
|
|
|
+
|
|
|
|
+ from celery.task.sets import TaskSet
|
|
|
|
+
|
|
|
|
+ ts = TaskSet(tasks=[
|
|
|
|
+ %(cls)s.subtask(args1, kwargs1, options1),
|
|
|
|
+ %(cls)s.subtask(args2, kwargs2, options2),
|
|
|
|
+ %(cls)s.subtask(args3, kwargs3, options3),
|
|
|
|
+ ...
|
|
|
|
+ %(cls)s.subtask(argsN, kwargsN, optionsN),
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ result = ts.apply_async()
|
|
|
|
+
|
|
|
|
+Thank you for your patience!
|
|
|
|
+
|
|
|
|
+"""
|
|
|
|
|
|
class subtask(AttributeDict):
|
|
class subtask(AttributeDict):
|
|
"""Class that wraps the arguments and execution options
|
|
"""Class that wraps the arguments and execution options
|
|
@@ -93,17 +117,23 @@ class TaskSet(UserList):
|
|
>>> list_of_return_values = taskset_result.join()
|
|
>>> list_of_return_values = taskset_result.join()
|
|
|
|
|
|
"""
|
|
"""
|
|
- task = None # compat
|
|
|
|
- task_name = None # compat
|
|
|
|
|
|
+ _task = None # compat
|
|
|
|
+ _task_name = None # compat
|
|
|
|
|
|
def __init__(self, task=None, tasks=None):
|
|
def __init__(self, task=None, tasks=None):
|
|
- # Previously TaskSet only supported applying one kind of task.
|
|
|
|
- # the signature then was TaskSet(task, arglist)
|
|
|
|
- # Convert the arguments to subtasks'.
|
|
|
|
if task is not None:
|
|
if task is not None:
|
|
- tasks = [subtask(task, *arglist) for arglist in tasks]
|
|
|
|
- self.task = task
|
|
|
|
- self.task_name = task.name
|
|
|
|
|
|
+ if hasattr(task, "__iter__"):
|
|
|
|
+ tasks = task
|
|
|
|
+ else:
|
|
|
|
+ # Previously TaskSet only supported applying one kind of task.
|
|
|
|
+ # the signature then was TaskSet(task, arglist),
|
|
|
|
+ # so convert the arguments to subtasks'.
|
|
|
|
+ tasks = [subtask(task, *arglist) for arglist in tasks]
|
|
|
|
+ task = self._task = registry.tasks[task.name]
|
|
|
|
+ self._task_name = task.name
|
|
|
|
+ warnings.warn(TASKSET_DEPRECATION_TEXT % {
|
|
|
|
+ "cls": task.__class__.__name__},
|
|
|
|
+ DeprecationWarning)
|
|
|
|
|
|
self.data = list(tasks)
|
|
self.data = list(tasks)
|
|
self.total = len(self.tasks)
|
|
self.total = len(self.tasks)
|
|
@@ -165,3 +195,18 @@ class TaskSet(UserList):
|
|
@property
|
|
@property
|
|
def tasks(self):
|
|
def tasks(self):
|
|
return self.data
|
|
return self.data
|
|
|
|
+
|
|
|
|
+ @property
|
|
|
|
+ def task(self):
|
|
|
|
+ warnings.warn(
|
|
|
|
+ "TaskSet.task is deprecated and will be removed in 1.4",
|
|
|
|
+ DeprecationWarning)
|
|
|
|
+ return self._task
|
|
|
|
+
|
|
|
|
+ @property
|
|
|
|
+ def task_name(self):
|
|
|
|
+ warnings.warn(
|
|
|
|
+ "TaskSet.task_name is deprecated and will be removed in 1.4",
|
|
|
|
+ DeprecationWarning)
|
|
|
|
+ return self._task_name
|
|
|
|
+
|