interaction.master.task¶
TaskResultType¶
TaskStatus¶
Task¶
- class ding.interaction.master.task.Task(http_engine: ding.interaction.base.network.HttpEngine, data: Mapping[str, Any], task_id: Optional[uuid.UUID] = None, before_task_start: Optional[Callable[[...], Mapping[str, Any]]] = None, after_task_start: Optional[Callable[[int, bool, int, Optional[str], Optional[Mapping[str, Any]]], Any]] = None, error_task_start: Optional[Callable[[requests.exceptions.RequestException], Any]] = None)[source]¶
- Overview:
Task object of the connections. Linking call is fully supported.
- Example:
A simple and common usage
>>> with master.new_connection('cnn1,', '127.0.0.1', 2333) as connection: >>> task = connection.new_task({'data': 233}) >>> # task is not sent yet >>> >>> task = task.on_complete(func1).on_fail(func2).on_complete(func3).start().join() >>> # task is completed or failed after this line >>> # when task completed : func1(result) --> func3(result) >>> # when task failed : func2(result)
- __init__(http_engine: ding.interaction.base.network.HttpEngine, data: Mapping[str, Any], task_id: Optional[uuid.UUID] = None, before_task_start: Optional[Callable[[...], Mapping[str, Any]]] = None, after_task_start: Optional[Callable[[int, bool, int, Optional[str], Optional[Mapping[str, Any]]], Any]] = None, error_task_start: Optional[Callable[[requests.exceptions.RequestException], Any]] = None)[source]¶
- Overview:
Constructor of Task
- Arguments:
http_engine (
HttpEngine): Http engine object used by the taskdata (
Mapping[str, Any]): Task data of the tasktask_id (
Optional[UUID]): Id of the taskbefore_task_start (
Optional[_BEFORE_HOOK_TYPE]): Callback to be executed before task start (None means do nothing)after_task_start (
Optional[_AFTER_HOOK_TYPE]): Callback to be executed after task start (None means do nothing)error_task_start (
Optional[_ERROR_HOOK_TYPE]): Callback to be executed when task start failed (None means do nothing)
- join() → ding.interaction.master.task.Task[source]¶
- Overview:
Wait until the task is completed or failed.
- Returns:
task (
Task): Self object, supporting linking call
- on_complete(callback: Callable[[Mapping[str, Any], Mapping[str, Any]], Any]) → ding.interaction.master.task.Task[source]¶
- Overview:
Execute the callback when the task completed. Multiple callbacks is supported by using linking call.
- Arguments:
callback (
Callable[[Mapping[str, Any], Mapping[str, Any]], Any]): Function to be executed when task completed.
- Returns:
task (
Task): Self object, supporting linking call
- on_fail(callback: Callable[[Mapping[str, Any], Mapping[str, Any]], Any]) → ding.interaction.master.task.Task[source]¶
- Overview:
Execute the callback when the task failed. Multiple callbacks is supported by using linking call.
- Arguments:
callback (
Callable[[Mapping[str, Any], Mapping[str, Any]], Any]): Function to be executed when task failed.
- Returns:
task (
Task): Self object, supporting linking call
- property result: Optional[Mapping[str, Any]]¶
- Overview:
Get task result of the current task, return None if task is not completed or failed.
- Returns:
result (
Optional[Mapping[str, Any]]): Task result (None when not completed or failed)
- start() → ding.interaction.master.task.Task[source]¶
- Overview:
Start current task.
- Returns:
task (
Task): Self object, supporting linking call
- property status: ding.interaction.master.task.TaskStatus¶
- Overview:
Get status of the current task
- Returns:
status (
TaskStatus): Task status
- property task: Mapping[str, Any]¶
- Overview:
Get task data of the current task
- Returns:
data (
Mapping[str, Any]): Task data