Main Task Executor
- class ska_csp_lmc_common.commands.main_task_executor.MainTaskExecutor(prefix='Main', workers=10, command_timeout=30, logger=None)
Bases:
objectAn asynchronous executor of tasks responsible for unpacking the CSP Main Task into Task/LeafTask and executing them. It can perform both parallel and serial tasks.
- __init__(prefix='Main', workers=10, command_timeout=30, logger=None)
Manage the execution of a main task in the CSP.
- Parameters:
prefix – the prefix to add to the thread name
logger – the logger to be used by this object.
- property timeout_event: Event
Retrun the timeout event
- set_command_timeout(timeout: int)
Set the command timeout
- get_command_timeout() int
Return the command timeout
- submit_main_task(task: Task | LeafTask, task_callback: Callable | None = None, task_abort_event: Event | None = None) tuple[ska_control_model.TaskStatus, str]
Submit a new CSP Main Task which may contain one or more Tasks.
- Parameters:
task – the Main Task to be executed.
task_callback – the callback to be called when the status or progress of the task execution changes
task_abort_event – external abort event propagated by the parent task executor
- Returns:
(TaskStatus, message)
- _is_abort_requested() bool
Return whether an abort has been requested either by the CSP main task executor or by the parent TaskExecutor.
- is_abort_requested() bool
Return whether an abort has been requested.
This public wrapper allows command handlers to distinguish a real task failure from a failure caused by an abort already in progress.
- _submit_task(task: Task, task_callback: Callable | None = None) tuple[ska_control_model.TaskStatus, str]
Submit a new Task.
- Parameters:
task – the Task to be executed.
task_callback – the callback to be called when the status or progress of the task execution changes
- Returns:
(TaskStatus, message)
- _sequential_execution(task: Task, task_callback: Callable | None = None) tuple[ska_control_model.TaskStatus, str]
Execute a sequential task.
- Parameters:
task – the Task to be executed.
task_callback – the callback invoked by the current task to report its progress or completion
- Returns:
(TaskStatus, message)
- _parallel_execution(task: Task, task_callback: Callable | None = None) tuple[ska_control_model.TaskStatus, str]
Execute a parallel task.
- Parameters:
task – the Task to be executed.
task_callback – the callback invoked by the current task to report its progress or completion
- Returns:
(TaskStatus, message)
- is_leaf_task_discarded(task: LeafTask, callback: Callable) bool
Verify if the main task timeout event or the skip event are set. If it is the case, invoke the callback with TaskStatus.REJECTED, result ResultCode.FAILED. In this case, the leaf task is not executed at all.
- Parameters:
task – the discarded task
callback – the callback to invoke
- Returns:
True if the timeout expired, otherwise False
- is_leaf_task_aborted(task: LeafTask, callback: Callable) bool
Verify if the abort event is set and in case invoke the callback with TaskStatus.ABORTED, result ResultCode.ABORTED. In this case, the leaf task is not executed at all.
- Parameters:
task – the aborted task
callback – the callback to invoke
- Returns:
True if the abort flag is set, otherwise False
- _internal_execution(task: LeafTask, task_callback: Callable | None = None)
Execute an internal CSP operation.
- Parameters:
task – The task to execute.
task_callback – Callback for task progress and completion.
- _device_execution(task: LeafTask, task_callback: Callable | None = None) None
Execute a LRC on a TANGO device through the DeviceTaskExecutor.
- Parameters:
LeafTask – the LeafTask to be executed on a device.
task_callback – the callback invoked by the current task to report its progress or completion
- Returns:
(TaskStatus, message)
- _check_skip_flag(task: Task)
Given that the skip_subtasks flag for the task or subtask is set, this function checks whether the input task has failed. If so, it ensures the skip_subtask_event flag is set, provided it is not already set. All subsequent subtasks will be skipped.
- Parameters:
task – sequential task
- shutdown(wait_flag: bool = True) None
Shutdown the main ThreadPoolExecutor
- Parameters:
wait_flag – blocking flag. If True (default) the thread is completed before return.
- clear_abort_flag()
Clear the abort flag
- abort(task_callback: Callable | None = None) tuple[ska_control_model.TaskStatus, str]
Abort the task executor.
- Parameters:
task_callback – the callback to be called when the status or progress of the task execution changes
- Returns:
(TaskStatus, message)
- _handle_task_exception(task_callback, message, status) tuple[ska_control_model.TaskStatus, str]
Helper to handle task failures.
- Parameters:
task_callback – the callback invoked by the current task to report its progress or completion
message – the message of the exception.
status – the TaskStatus of the Task.
- Returns:
(TaskStatus, message)