You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module provides a basic class library for task grouping, mainly includes 2 classes:
7
+
This module provides a basic class library for task grouping, includes 2 classes:
8
8
9
-
* TaskContainer - Organizes a batch of task groups, including the serial/parallel structures, and carries the arguments information for each task unit to run.
9
+
- **TaskContainer**
10
10
11
-
*ITaskLoader - This is an abstract base class for implementing a concrete loader class to load a task tree from Dict/JSON to TaskContainer.
11
+
Organizes a batch of task groups, including the serial/parallel structures, and carries the arguments information for each task unit to run.
12
12
13
-
|
13
+
- **ITaskLoader**
14
+
15
+
This is an abstract base class for implementing a concrete loader class to load a task tree from Dict/JSON to TaskContainer.
16
+
17
+
----
14
18
15
19
| Homepage and documentation: https://github.com/DataBooster/PyWebApi
16
20
| Copyright (c) 2020 Abel Cheng
@@ -23,7 +27,12 @@
23
27
24
28
25
29
classTaskContainer(object):
30
+
"""Organizes a batch of task groups, including the serial/parallel structures, and carries the arguments information for each task unit to run.
26
31
32
+
:param func: A callable to be executed by the task.
33
+
:param merge_fn: A function for merging pipeline arguments (a dictionary ``[Dict[str, Any]``) with user input arguments (a dictionary ``[Dict[str, Any]``), it must return a new dictionary ``[Dict[str, Any]``.
34
+
:param thread_pool: An instance of ``ThreadPoolExecutor`` for executing any parallel task group. This argument is required, otherwise any parallel task group will actually be executed serially.
self.merge_fn=merge_fn# A function for merging pipeline arguments with user input kw_args
38
47
39
48
40
49
@property
@@ -59,6 +68,15 @@ def task_group(self, group):
59
68
60
69
61
70
defrun(self, pipeargs:dict={}):
71
+
"""Execute all tasks and task groups in the specified order (serial/parallel) and assemble their results into a tree structure corresponding to the input payload.
72
+
73
+
:param pipeargs: (optional) If the result of the previous task is a dictionary ``[Dict[str, Any]``, it can be piped to current task or task group at run time and merged into the user input arguments.
74
+
75
+
- If current task is a serial group, the first subtask will receive the pipeline arguments, and the result of the first subtask will be used as the pipeline arguments of the second subtask, and so on.
76
+
- If current task is a parallel group, all subtasks will receive this same pipeline arguments.
77
+
78
+
:return: All results will be assembled into a tree structure corresponding to the input payload.
"""This is an abstract base class for implementing a concrete loader class to load a task tree from Dict/JSON to ``TaskContainer``."""
133
155
134
156
@abstractmethod
135
157
defcreate_base_container(self) ->TaskContainer:
158
+
"""This method is used to create a new container and initialize the most basic properties of ``TaskContainer``: ``func``, ``merge_fn``, ``thread_pool``, etc.
"""This method is used to determine whether the task node is a leaf task (single task).
172
+
If so, it should return a tuple containing three elements:
173
+
174
+
1. The first element must be a tuple containing the positional arguments to be passed to the task. If the position argument is not needed at all, please put ``()``;
175
+
2. The second element must be a dictionary containing keyworded arguments to be passed to the task. If there are no arguments, please put ``{}``;
176
+
3. The third element must be a Boolean value to indicate whether to merge the execution result of the previous task as a pipeline argument into the user input keyworded arguments.
177
+
178
+
If the task node is NOT a leaf task, this method should return ``None``.
179
+
180
+
:param task_node: A node of task tree - ``Dict[str, Any]``.
raiseTypeError("extract_single_task must return Tuple[tuple, Dict[str, Any], bool] if the current node is a leaf task, otherwise it must return None.")
0 commit comments