diff --git a/src/ska_tango_base/base/component_manager.py b/src/ska_tango_base/base/component_manager.py index ea7a6a32e2eab1879dddb00296cf1c9862cd2c11..c19618b46b73f0e2967a88a326d6389465242a91 100644 --- a/src/ska_tango_base/base/component_manager.py +++ b/src/ska_tango_base/base/component_manager.py @@ -23,9 +23,7 @@ The basic model is: the component to change behaviour and/or state; and it *monitors* its component by keeping track of its state. """ -import logging -from typing import Any, Callable, Optional, Tuple -from ska_tango_base.base.op_state_model import OpStateModel +from typing import Any, Optional, Tuple from ska_tango_base.commands import BaseCommand, ResultCode @@ -239,51 +237,3 @@ class BaseComponentManager: :rtype: tuple """ return self.queue_manager.enqueue_task(task, argin=argin) - - -class QueueWorkerComponentManager(BaseComponentManager): - """A component manager that configres the queue manager.""" - - def __init__( - self, - op_state_model: Optional[OpStateModel], - logger: logging.Logger, - max_queue_size: int, - num_workers: int, - push_change_event: Optional[Callable], - *args, - **kwargs - ): - """Component manager that configures the queue. - - :param op_state_model: The ops state model - :type op_state_model: OpStateModel - :param logger: Logger to use - :type logger: logging.Logger - :param max_queue_size: The size of the queue - :type max_queue_size: int - :param num_workers: The number of workers - :type num_workers: int - :param push_change_event: A method that will be called when attributes are updated - :type push_change_event: Callable - """ - self.logger = logger - self.max_queue_size = max_queue_size - self.num_workers = num_workers - self.push_change_event = push_change_event - super().__init__(op_state_model, *args, **kwargs) - - def create_queue_manager(self) -> QueueManager: - """Create a QueueManager. - - Create the QueueManager with the queue configured as needed. - - :return: The queue manager - :rtype: QueueManager - """ - return QueueManager( - max_queue_size=self.max_queue_size, - num_workers=self.num_workers, - logger=self.logger, - push_change_event=self.push_change_event, - ) diff --git a/src/ska_tango_base/base/reference_component_manager.py b/src/ska_tango_base/base/reference_component_manager.py index 065a348bd38821aa72c3006ecfe63b5322a4221a..0326d822fd20ac0b8d1b7a0b145f21898aaa6c1f 100644 --- a/src/ska_tango_base/base/reference_component_manager.py +++ b/src/ska_tango_base/base/reference_component_manager.py @@ -1,12 +1,15 @@ """ -This module provided a reference implementation of a BaseComponentManager. +This module provided reference implementations of a BaseComponentManager. It is provided for explanatory purposes, and to support testing of this package. """ import functools +import logging +from typing import Optional, Callable -from ska_tango_base.base import BaseComponentManager +from ska_tango_base.base import BaseComponentManager, OpStateModel +from ska_tango_base.base.task_queue_manager import QueueManager from ska_tango_base.control_model import PowerMode from ska_tango_base.faults import ComponentFault @@ -389,3 +392,51 @@ class ReferenceBaseComponentManager(BaseComponentManager): This is a callback hook. """ self.op_state_model.perform_action("component_fault") + + +class QueueWorkerComponentManager(BaseComponentManager): + """A component manager that configres the queue manager.""" + + def __init__( + self, + op_state_model: Optional[OpStateModel], + logger: logging.Logger, + max_queue_size: int, + num_workers: int, + push_change_event: Optional[Callable], + *args, + **kwargs + ): + """Component manager that configures the queue. + + :param op_state_model: The ops state model + :type op_state_model: OpStateModel + :param logger: Logger to use + :type logger: logging.Logger + :param max_queue_size: The size of the queue + :type max_queue_size: int + :param num_workers: The number of workers + :type num_workers: int + :param push_change_event: A method that will be called when attributes are updated + :type push_change_event: Callable + """ + self.logger = logger + self.max_queue_size = max_queue_size + self.num_workers = num_workers + self.push_change_event = push_change_event + super().__init__(op_state_model, *args, **kwargs) + + def create_queue_manager(self) -> QueueManager: + """Create a QueueManager. + + Create the QueueManager with the queue configured as needed. + + :return: The queue manager + :rtype: QueueManager + """ + return QueueManager( + max_queue_size=self.max_queue_size, + num_workers=self.num_workers, + logger=self.logger, + push_change_event=self.push_change_event, + ) diff --git a/tests/long_running_tasks/reference_base_device.py b/tests/long_running_tasks/reference_base_device.py index cf8882e3d0094637afb61661ffbbb2b4b125c12c..547c5956bbf60fedde22a00e870696aa25544912 100644 --- a/tests/long_running_tasks/reference_base_device.py +++ b/tests/long_running_tasks/reference_base_device.py @@ -13,9 +13,7 @@ import time from tango.server import command from tango import DebugIt -from ska_tango_base.base.component_manager import ( - QueueWorkerComponentManager, -) +from ska_tango_base.base.reference_component_manager import QueueWorkerComponentManager from ska_tango_base.base.base_device import SKABaseDevice from ska_tango_base.base.task_queue_manager import ResultCode from ska_tango_base.commands import ResponseCommand diff --git a/tests/long_running_tasks/test_task_queue_manager.py b/tests/long_running_tasks/test_task_queue_manager.py index b1c94d7f3ab06a62e035883063d458d39e622a16..a9fad70e82b1c48d9957cff5eae040b0198c7cfc 100644 --- a/tests/long_running_tasks/test_task_queue_manager.py +++ b/tests/long_running_tasks/test_task_queue_manager.py @@ -10,7 +10,7 @@ from ska_tango_base.base.task_queue_manager import ( TaskResult, TaskState, ) -from ska_tango_base.base.component_manager import QueueWorkerComponentManager +from ska_tango_base.base.reference_component_manager import QueueWorkerComponentManager from ska_tango_base.commands import BaseCommand logger = logging.getLogger(__name__)