From c32eb2e955e62fcb6b78b9475a0d4c548a87256d Mon Sep 17 00:00:00 2001 From: Maxim V4S Date: Mon, 2 Sep 2024 14:52:40 +0300 Subject: [PATCH] feat: stop running item api --- qualibrate_runner/api/routes/others.py | 7 +++++++ qualibrate_runner/core/run_job.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qualibrate_runner/api/routes/others.py b/qualibrate_runner/api/routes/others.py index e1aa780..2fe7ece 100644 --- a/qualibrate_runner/api/routes/others.py +++ b/qualibrate_runner/api/routes/others.py @@ -20,6 +20,13 @@ def check_running( return state.is_running +@others_router.post("/stop") +def stop_running(state: Annotated[State, Depends(get_state)]) -> bool: + if state.run_item is None: + return False + return bool(state.run_item.stop()) + + @others_router.post( "/record_state_update", description=( diff --git a/qualibrate_runner/core/run_job.py b/qualibrate_runner/core/run_job.py index 2716f1e..35e003f 100644 --- a/qualibrate_runner/core/run_job.py +++ b/qualibrate_runner/core/run_job.py @@ -24,6 +24,12 @@ def validate_input_parameters( ) +def get_active_library_or_error() -> QualibrationLibrary: + if QualibrationLibrary.active_library is None: + raise RuntimeError("Qualibration library is not exist") + return QualibrationLibrary.active_library + + def run_node( node: QualibrationNode, passed_input_parameters: Mapping[str, Any], @@ -38,7 +44,7 @@ def run_node( started_at=datetime.now(), ) try: - library = QualibrationLibrary.active_library + library = get_active_library_or_error() node = library.nodes[node.name] result = library.run_node( node.name, node.parameters_class(**passed_input_parameters) @@ -85,7 +91,7 @@ def run_workflow( ) state.run_item = workflow try: - library = QualibrationLibrary.active_library + library = get_active_library_or_error() workflow = library.graphs[workflow.name] result = library.run_graph( workflow.name,