Command Tracker
This module implements the CommandTracker and its supporting classes/functions.
This module is deprecated and will be removed in future release of ska-tango-base. Use
ska_tango_base.type_hints.CommandTrackerProtocol for type hints instead.
- class ska_tango_base.base.command_tracker.CommandTracker[source]
A class for keeping track of the state and progress of long runnning commands.
- __init__(queue_changed_callback: Callable[[list[tuple[str, str]]], None], status_changed_callback: Callable[[list[tuple[str, TaskStatus]]], None], progress_changed_callback: Callable[[list[tuple[str, int]]], None], result_callback: Callable[[str, JSONData], None], exception_callback: Callable[[str, Exception], None] | None = None, event_callback: Callable[[str, JSONData], None] | None = None, update_user_attributes_callback: Callable[[dict[str, _CommandData], dict[str, _CommandData], dict[str, _CommandData]], None] | None = None, removal_time: float = 10.0) None[source]
Initialise a new instance.
- Parameters:
queue_changed_callback – called when the queue changes
status_changed_callback – called when the status changes
progress_changed_callback – called when the progress changes
result_callback – called when command finishes
exception_callback – called in the event of an exception
event_callback – called for any and all change events
update_user_attributes_callback – called for any and all change events
removal_time – timer
- new_command(command_name: str, completed_callback: Callable[[], None] | None = None) str[source]
Create a new command.
- Parameters:
command_name – the command name
completed_callback – an optional callback for command completion
- Returns:
a unique command id
- update_command_info(command_id: str, status: TaskStatus | None = None, progress: int | None = None, result: JSONData | None = None, exception: Exception | None = None) None[source]
Update status information on the command.
- Parameters:
command_id – the unique command id
status – the status of the asynchronous task
progress – the progress of the asynchronous task
result – the result of the completed asynchronous task
exception – any exception caught in the running task
- Raises:
TypeError – if status is not the TaskStatus enum type
- has_current_thread_locked() bool[source]
Has CommandTracker locked the current thread for updating the LRC attributes.
- Returns:
if current thread is locked by CommandTracker.
- property commands_in_queue: list[tuple[str, str]]
Return a list of commands in the queue.
- Returns:
a list of (command_id, command_name) tuples, ordered by when invoked.
- property command_statuses: list[tuple[str, TaskStatus]]
Return a list of command statuses for commands in the queue.
- Returns:
a list of (command_id, status) tuples, ordered by when invoked.
- property command_progresses: list[tuple[str, int]]
Return a list of command progresses for commands in the queue.
- Returns:
a list of (command_id, progress) tuples, ordered by when invoked.
- property command_result: tuple[str, JSONData] | None
Return the result of the most recently completed command.
- Returns:
a (command_id, result) tuple. If no command has completed yet, then None.
- property command_exception: tuple[str, Exception] | None
Return the most recent exception, if any.
- Returns:
a (command_id, exception) tuple. If no command has raised an uncaught exception, then None.
- get_command_status(command_id: str) TaskStatus[source]
Return the current status of a running command.
- Parameters:
command_id – the unique command id
- Returns:
a status of the asynchronous task.
- evict_command(command_id: str) bool[source]
Add to the list of commands not to be reported by the LRC attributes.
This is used to ensure we don’t overflow the attribute bounds when there are too many finished commands lingering for the removal_period.
- Parameters:
command_id – the unique command id
- Returns:
True if the command was not already evicted.