diff --git a/docs/user/reference/openapi.yaml b/docs/user/reference/openapi.yaml index fa51219c6..921bf3c7c 100644 --- a/docs/user/reference/openapi.yaml +++ b/docs/user/reference/openapi.yaml @@ -15,8 +15,8 @@ components: title: Protocols type: array required: - - name - - protocols + - name + - protocols title: DeviceModel type: object DeviceResponse: @@ -26,11 +26,11 @@ components: devices: description: Devices available to use in plans items: - $ref: '#/components/schemas/DeviceModel' + $ref: "#/components/schemas/DeviceModel" title: Devices type: array required: - - devices + - devices title: DeviceResponse type: object EnvironmentResponse: @@ -42,14 +42,14 @@ components: title: Initialized type: boolean required: - - initialized + - initialized title: EnvironmentResponse type: object HTTPValidationError: properties: detail: items: - $ref: '#/components/schemas/ValidationError' + $ref: "#/components/schemas/ValidationError" title: Detail type: array title: HTTPValidationError @@ -71,7 +71,7 @@ components: title: Schema type: object required: - - name + - name title: PlanModel type: object PlanResponse: @@ -81,14 +81,14 @@ components: plans: description: Plans available to use by a worker items: - $ref: '#/components/schemas/PlanModel' + $ref: "#/components/schemas/PlanModel" title: Plans type: array required: - - plans + - plans title: PlanResponse type: object - RunPlan: + Task: additionalProperties: false description: Task that will run a plan properties: @@ -101,8 +101,8 @@ components: title: Params type: object required: - - name - title: RunPlan + - name + title: Task type: object StateChangeRequest: additionalProperties: false @@ -114,13 +114,13 @@ components: title: Defer type: boolean new_state: - $ref: '#/components/schemas/WorkerState' + $ref: "#/components/schemas/WorkerState" reason: description: The reason for the current run to be aborted title: Reason type: string required: - - new_state + - new_state title: StateChangeRequest type: object TaskResponse: @@ -132,7 +132,7 @@ components: title: Task Id type: string required: - - task_id + - task_id title: TaskResponse type: object TrackableTask: @@ -158,7 +158,7 @@ components: title: Task Id type: string required: - - task_id + - task_id title: TrackableTask type: object ValidationError: @@ -166,8 +166,8 @@ components: loc: items: anyOf: - - type: string - - type: integer + - type: string + - type: integer title: Location type: array msg: @@ -177,24 +177,24 @@ components: title: Error Type type: string required: - - loc - - msg - - type + - loc + - msg + - type title: ValidationError type: object WorkerState: description: The state of the Worker. enum: - - IDLE - - RUNNING - - PAUSING - - PAUSED - - HALTING - - STOPPING - - ABORTING - - SUSPENDING - - PANICKED - - UNKNOWN + - IDLE + - RUNNING + - PAUSING + - PAUSED + - HALTING + - STOPPING + - ABORTING + - SUSPENDING + - PANICKED + - UNKNOWN title: WorkerState type: string WorkerTask: @@ -217,11 +217,11 @@ paths: description: Retrieve information about all available devices. operationId: get_devices_devices_get responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/DeviceResponse' + $ref: "#/components/schemas/DeviceResponse" description: Successful Response summary: Get Devices /devices/{name}: @@ -229,31 +229,31 @@ paths: description: Retrieve information about a devices by its (unique) name. operationId: get_device_by_name_devices__name__get parameters: - - in: path - name: name - required: true - schema: - title: Name - type: string + - in: path + name: name + required: true + schema: + title: Name + type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/DeviceModel' + $ref: "#/components/schemas/DeviceModel" description: Successful Response - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Get Device By Name /environment: delete: operationId: delete_environment_environment_delete responses: - '200': + "200": content: application/json: schema: {} @@ -262,11 +262,11 @@ paths: get: operationId: get_environment_environment_get responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/EnvironmentResponse' + $ref: "#/components/schemas/EnvironmentResponse" description: Successful Response summary: Get Environment /plans: @@ -274,11 +274,11 @@ paths: description: Retrieve information about all available plans. operationId: get_plans_plans_get responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/PlanResponse' + $ref: "#/components/schemas/PlanResponse" description: Successful Response summary: Get Plans /plans/{name}: @@ -286,24 +286,24 @@ paths: description: Retrieve information about a plan by its (unique) name. operationId: get_plan_by_name_plans__name__get parameters: - - in: path - name: name - required: true - schema: - title: Name - type: string + - in: path + name: name + required: true + schema: + title: Name + type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/PlanModel' + $ref: "#/components/schemas/PlanModel" description: Successful Response - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Get Plan By Name /tasks: @@ -317,70 +317,70 @@ paths: name: count params: detectors: - - x + - x schema: - $ref: '#/components/schemas/RunPlan' + $ref: "#/components/schemas/Task" required: true responses: - '201': + "201": content: application/json: schema: - $ref: '#/components/schemas/TaskResponse' + $ref: "#/components/schemas/TaskResponse" description: Successful Response - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Submit Task /tasks/{task_id}: delete: operationId: delete_submitted_task_tasks__task_id__delete parameters: - - in: path - name: task_id - required: true - schema: - title: Task Id - type: string + - in: path + name: task_id + required: true + schema: + title: Task Id + type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/TaskResponse' + $ref: "#/components/schemas/TaskResponse" description: Successful Response - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Delete Submitted Task get: description: Retrieve a task operationId: get_task_tasks__task_id__get parameters: - - in: path - name: task_id - required: true - schema: - title: Task Id - type: string + - in: path + name: task_id + required: true + schema: + title: Task Id + type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/TrackableTask' + $ref: "#/components/schemas/TrackableTask" description: Successful Response - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Get Task /worker/state: @@ -388,15 +388,16 @@ paths: description: Get the State of the Worker operationId: get_state_worker_state_get responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/WorkerState' + $ref: "#/components/schemas/WorkerState" description: Successful Response summary: Get State put: - description: "Request that the worker is put into a particular state.\nReturns\ + description: + "Request that the worker is put into a particular state.\nReturns\ \ the state of the worker at the end of the call.\n\n- **The following transitions\ \ are allowed and return 202: Accepted**\n- If the worker is **PAUSED**, new_state\ \ may be **RUNNING** to resume.\n- If the worker is **RUNNING**, new_state\ @@ -415,35 +416,35 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/StateChangeRequest' + $ref: "#/components/schemas/StateChangeRequest" required: true responses: - '202': + "202": content: application/json: schema: - $ref: '#/components/schemas/WorkerState' + $ref: "#/components/schemas/WorkerState" description: Successful Response detail: Transition requested - '400': + "400": description: Bad Request detail: Transition not allowed - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Set State /worker/task: get: operationId: get_active_task_worker_task_get responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/WorkerTask' + $ref: "#/components/schemas/WorkerTask" description: Successful Response summary: Get Active Task put: @@ -452,22 +453,22 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/WorkerTask' + $ref: "#/components/schemas/WorkerTask" required: true responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/WorkerTask' + $ref: "#/components/schemas/WorkerTask" description: Successful Response - '409': + "409": description: Conflict worker: already active - '422': + "422": content: application/json: schema: - $ref: '#/components/schemas/HTTPValidationError' + $ref: "#/components/schemas/HTTPValidationError" description: Validation Error summary: Update Task diff --git a/src/blueapi/cli/cli.py b/src/blueapi/cli/cli.py index 3e2e458c9..c8410e9c1 100644 --- a/src/blueapi/cli/cli.py +++ b/src/blueapi/cli/cli.py @@ -23,7 +23,7 @@ print_schema_as_yaml, write_schema_as_yaml, ) -from blueapi.worker import ProgressEvent, RunPlan, WorkerEvent, WorkerState +from blueapi.worker import ProgressEvent, Task, WorkerEvent, WorkerState from .rest import BlueapiRestClient @@ -182,7 +182,7 @@ def store_finished_event(event: WorkerEvent) -> None: finished_event.append(event) parameters = parameters or "{}" - task = RunPlan(name=name, params=json.loads(parameters)) + task = Task(name=name, params=json.loads(parameters)) resp = client.create_task(task) task_id = resp.task_id diff --git a/src/blueapi/cli/rest.py b/src/blueapi/cli/rest.py index 7c4eeef81..b364edc49 100644 --- a/src/blueapi/cli/rest.py +++ b/src/blueapi/cli/rest.py @@ -12,7 +12,7 @@ TaskResponse, WorkerTask, ) -from blueapi.worker import RunPlan, TrackableTask, WorkerState +from blueapi.worker import Task, TrackableTask, WorkerState from .amq import BlueskyRemoteError @@ -56,15 +56,15 @@ def set_state( data={"new_state": state, "defer": defer}, ) - def get_task(self, task_id: str) -> TrackableTask[RunPlan]: + def get_task(self, task_id: str) -> TrackableTask[Task]: return self._request_and_deserialize( - f"/tasks/{task_id}", TrackableTask[RunPlan] + f"/tasks/{task_id}", TrackableTask[Task] ) def get_active_task(self) -> WorkerTask: return self._request_and_deserialize("/worker/task", WorkerTask) - def create_task(self, task: RunPlan) -> TaskResponse: + def create_task(self, task: Task) -> TaskResponse: return self._request_and_deserialize( "/tasks", TaskResponse, diff --git a/src/blueapi/service/handler.py b/src/blueapi/service/handler.py index bab1eba34..19f1b8b37 100644 --- a/src/blueapi/service/handler.py +++ b/src/blueapi/service/handler.py @@ -17,7 +17,7 @@ from blueapi.service.model import DeviceModel, PlanModel, WorkerTask from blueapi.worker.event import WorkerState from blueapi.worker.reworker import RunEngineWorker -from blueapi.worker.task import RunPlan +from blueapi.worker.task import Task from blueapi.worker.worker import TrackableTask, Worker LOGGER = logging.getLogger(__name__) @@ -102,7 +102,7 @@ def devices(self) -> List[DeviceModel]: def get_device(self, name: str) -> DeviceModel: return DeviceModel.from_device(self._context.devices[name]) - def submit_task(self, task: RunPlan) -> str: + def submit_task(self, task: Task) -> str: return self._worker.submit_task(task) def clear_pending_task(self, task_id: str) -> str: diff --git a/src/blueapi/service/handler_base.py b/src/blueapi/service/handler_base.py index 8ca15f1a8..00e215c58 100644 --- a/src/blueapi/service/handler_base.py +++ b/src/blueapi/service/handler_base.py @@ -3,7 +3,7 @@ from blueapi.service.model import DeviceModel, PlanModel, WorkerTask from blueapi.worker.event import WorkerState -from blueapi.worker.task import RunPlan +from blueapi.worker.task import Task from blueapi.worker.worker import TrackableTask @@ -37,7 +37,7 @@ def get_device(self, name: str) -> DeviceModel: """ @abstractmethod - def submit_task(self, task: RunPlan) -> str: + def submit_task(self, task: Task) -> str: """ Submit a task to be run on begin_task """ diff --git a/src/blueapi/service/main.py b/src/blueapi/service/main.py index d02dfc2f1..710264bb7 100644 --- a/src/blueapi/service/main.py +++ b/src/blueapi/service/main.py @@ -16,7 +16,7 @@ from super_state_machine.errors import TransitionError from blueapi.config import ApplicationConfig -from blueapi.worker import RunPlan, TrackableTask, WorkerState +from blueapi.worker import Task, TrackableTask, WorkerState from .handler_base import BlueskyHandler from .model import ( @@ -141,8 +141,8 @@ def get_device_by_name(name: str, handler: BlueskyHandler = Depends(get_handler) def submit_task( request: Request, response: Response, - task: RunPlan = Body( - ..., example=RunPlan(name="count", params={"detectors": ["x"]}) + task: Task = Body( + ..., example=Task(name="count", params={"detectors": ["x"]}) ), handler: BlueskyHandler = Depends(get_handler), ): diff --git a/src/blueapi/service/subprocess_handler.py b/src/blueapi/service/subprocess_handler.py index 151d7cd9a..2fc47f027 100644 --- a/src/blueapi/service/subprocess_handler.py +++ b/src/blueapi/service/subprocess_handler.py @@ -9,7 +9,7 @@ from blueapi.service.handler_base import BlueskyHandler, HandlerNotStartedError from blueapi.service.model import DeviceModel, PlanModel, WorkerTask from blueapi.worker.event import WorkerState -from blueapi.worker.task import RunPlan +from blueapi.worker.task import Task from blueapi.worker.worker import TrackableTask set_start_method("spawn", force=True) @@ -78,7 +78,7 @@ def devices(self) -> List[DeviceModel]: def get_device(self, name: str) -> DeviceModel: return self._run_in_subprocess(get_device, [name]) - def submit_task(self, task: RunPlan) -> str: + def submit_task(self, task: Task) -> str: return self._run_in_subprocess(submit_task, [task]) def clear_pending_task(self, task_id: str) -> str: @@ -135,7 +135,7 @@ def get_device(name: str) -> DeviceModel: return get_handler().get_device(name) -def submit_task(task: RunPlan) -> str: +def submit_task(task: Task) -> str: return get_handler().submit_task(task) diff --git a/src/blueapi/worker/__init__.py b/src/blueapi/worker/__init__.py index 78309230e..a598dbfc6 100644 --- a/src/blueapi/worker/__init__.py +++ b/src/blueapi/worker/__init__.py @@ -1,7 +1,7 @@ from .event import ProgressEvent, StatusView, TaskStatus, WorkerEvent, WorkerState from .multithread import run_worker_in_own_thread from .reworker import RunEngineWorker -from .task import RunPlan, Task +from .task import Task from .worker import TrackableTask, Worker from .worker_busy_error import WorkerBusyError @@ -10,7 +10,6 @@ "RunEngineWorker", "Task", "Worker", - "RunPlan", "WorkerEvent", "WorkerState", "StatusView", diff --git a/src/blueapi/worker/task.py b/src/blueapi/worker/task.py index 84f5a21cd..6adbbe1db 100644 --- a/src/blueapi/worker/task.py +++ b/src/blueapi/worker/task.py @@ -32,16 +32,6 @@ def do_task(self, ctx: BlueskyContext) -> None: ctx.run_engine(wrapped_plan_generator) -# Here for backward compatibility pending -# https://github.com/DiamondLightSource/blueapi/issues/253 -class RunPlan(Task): - """ - Task that will run a plan - """ - - ... - - def _lookup_params(ctx: BlueskyContext, task: Task) -> BaseModel: """ Checks plan parameters against context diff --git a/tests/service/test_rest_api.py b/tests/service/test_rest_api.py index ea3aa3deb..56c4b99b8 100644 --- a/tests/service/test_rest_api.py +++ b/tests/service/test_rest_api.py @@ -13,10 +13,10 @@ from blueapi.service.handler import Handler from blueapi.service.main import get_handler, setup_handler, teardown_handler from blueapi.service.model import WorkerTask -from blueapi.worker.task import RunPlan +from blueapi.worker.task import Task from src.blueapi.worker import WorkerState -_TASK = RunPlan(name="count", params={"detectors": ["x"]}) +_TASK = Task(name="count", params={"detectors": ["x"]}) def test_get_plans(handler: Handler, client: TestClient) -> None: diff --git a/tests/service/test_subprocess_handler.py b/tests/service/test_subprocess_handler.py index 15fdcdab4..91ec030f7 100644 --- a/tests/service/test_subprocess_handler.py +++ b/tests/service/test_subprocess_handler.py @@ -7,7 +7,7 @@ from blueapi.service.model import DeviceModel, PlanModel, WorkerTask from blueapi.service.subprocess_handler import SubprocessHandler from blueapi.worker.event import WorkerState -from blueapi.worker.task import RunPlan +from blueapi.worker.task import Task from blueapi.worker.worker import TrackableTask @@ -63,7 +63,7 @@ def devices(self) -> List[DeviceModel]: def get_device(self, name: str) -> DeviceModel: return DeviceModel(name="device1", protocols=[]) - def submit_task(self, task: RunPlan) -> str: + def submit_task(self, task: Task) -> str: return "0" def clear_pending_task(self, task_id: str) -> str: @@ -90,7 +90,7 @@ def cancel_active_task(self, failure: bool, reason: Optional[str]) -> None: ... def pending_tasks(self) -> List[TrackableTask]: return [ TrackableTask( - task_id="abc", task=RunPlan(name="sleep", params={"time": 0.0}) + task_id="abc", task=Task(name="sleep", params={"time": 0.0}) ) ] @@ -137,8 +137,8 @@ def run_in_same_process(func, args=None): assert sp_handler.get_device("name") == dummy_handler.get_device("name") assert sp_handler.submit_task( - RunPlan(name="sleep", params={"time": 0.0}) - ) == dummy_handler.submit_task(RunPlan(name="sleep", params={"time": 0.0})) + Task(name="sleep", params={"time": 0.0}) + ) == dummy_handler.submit_task(Task(name="sleep", params={"time": 0.0})) assert sp_handler.clear_pending_task("task_id") == dummy_handler.clear_pending_task( "task_id" diff --git a/tests/worker/test_reworker.py b/tests/worker/test_reworker.py index 6dad9b132..42e8fe95d 100644 --- a/tests/worker/test_reworker.py +++ b/tests/worker/test_reworker.py @@ -11,7 +11,6 @@ from blueapi.worker import ( ProgressEvent, RunEngineWorker, - RunPlan, Task, TaskStatus, TrackableTask, @@ -21,13 +20,13 @@ WorkerState, ) -_SIMPLE_TASK = RunPlan(name="sleep", params={"time": 0.0}) -_LONG_TASK = RunPlan(name="sleep", params={"time": 1.0}) -_INDEFINITE_TASK = RunPlan( +_SIMPLE_TASK = Task(name="sleep", params={"time": 0.0}) +_LONG_TASK = Task(name="sleep", params={"time": 1.0}) +_INDEFINITE_TASK = Task( name="set_absolute", params={"movable": "fake_device", "value": 4.0}, ) -_FAILING_TASK = RunPlan(name="failing_plan", params={}) +_FAILING_TASK = Task(name="failing_plan", params={}) class FakeDevice: @@ -259,7 +258,7 @@ def test_no_additional_progress_events_after_complete(worker: Worker): progress_events: List[ProgressEvent] = [] worker.progress_events.subscribe(lambda event, id: progress_events.append(event)) - task: Task = RunPlan( + task: Task = Task( name="move", params={"moves": {"additional_status_device": 5.0}} ) task_id = worker.submit_task(task) @@ -344,7 +343,7 @@ def test_worker_and_data_events_produce_in_order(worker: Worker) -> None: def assert_running_count_plan_produces_ordered_worker_and_data_events( expected_events: List[Union[WorkerEvent, DataEvent]], worker: Worker, - task: Task = RunPlan(name="count", params={"detectors": ["image_det"], "num": 1}), + task: Task = Task(name="count", params={"detectors": ["image_det"], "num": 1}), timeout: float = 5.0, ) -> None: event_streams: List[EventStream[Any, int]] = [