Skip to content

Commit

Permalink
feat: use library rescan
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-v4s committed Sep 25, 2024
1 parent 5ce921c commit ff8bb40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
21 changes: 10 additions & 11 deletions qualibrate_runner/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ def get_state() -> State:


@cache
def get_library(
def get_cached_library(
settings: Annotated[QualibrateRunnerSettings, Depends(get_settings)],
) -> QualibrationLibrary:
return settings.calibration_library_resolver(
settings.calibration_library_folder
)


@cache
def get_library(
library: Annotated[QualibrationLibrary, Depends(get_cached_library)],
rescan: bool = False,
) -> QualibrationLibrary:
if rescan:
library.rescan()
return library


def get_nodes(
library: Annotated[QualibrationLibrary, Depends(get_library)],
) -> Mapping[str, QualibrationNode]:
return cast(Mapping[str, QualibrationNode], library.get_nodes())


@cache
def get_graphs(
library: Annotated[QualibrationLibrary, Depends(get_library)],
) -> Mapping[str, QualibrationGraph]:
Expand All @@ -61,11 +68,3 @@ def get_graph(
status_code=422, detail=f"Unknown graph name {name}"
)
return graph


CACHED_DEPENDENCIES = (get_library, get_nodes, get_graphs)


def cache_clear() -> None:
for func in CACHED_DEPENDENCIES:
func.cache_clear()
20 changes: 0 additions & 20 deletions qualibrate_runner/api/routes/get_runnables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
from qualibrate.qualibration_graph import QualibrationGraph
from qualibrate.qualibration_node import QualibrationNode

from qualibrate_runner.api.dependencies import (
cache_clear,
get_library,
)
from qualibrate_runner.api.dependencies import (
get_graph as get_qgraph,
)
Expand All @@ -20,38 +16,22 @@
from qualibrate_runner.api.dependencies import (
get_nodes as get_qnodes,
)
from qualibrate_runner.config import (
QualibrateRunnerSettings,
get_settings,
)

get_runnables_router = APIRouter()


@get_runnables_router.get("/get_nodes")
def get_nodes(
nodes: Annotated[Mapping[str, QualibrationNode], Depends(get_qnodes)],
settings: Annotated[QualibrateRunnerSettings, Depends(get_settings)],
rescan: bool = False,
) -> Mapping[str, Any]:
if rescan:
cache_clear()
library = get_library(settings)
nodes = get_qnodes(library)
return {node_name: node.serialize() for node_name, node in nodes.items()}


@get_runnables_router.get("/get_graphs")
def get_graphs(
graphs: Annotated[Mapping[str, QualibrationNode], Depends(get_qgraphs)],
settings: Annotated[QualibrateRunnerSettings, Depends(get_settings)],
rescan: bool = False,
cytoscape: bool = False,
) -> Mapping[str, Any]:
if rescan:
cache_clear()
library = get_library(settings)
graphs = get_qgraphs(library)
return {
graph_name: graph.serialize(cytoscape=cytoscape)
for graph_name, graph in graphs.items()
Expand Down
11 changes: 7 additions & 4 deletions qualibrate_runner/core/run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from qualibrate.qualibration_graph import QualibrationGraph
from qualibrate.qualibration_library import QualibrationLibrary
from qualibrate.qualibration_node import QualibrationNode

from qualibrate.run_summary.node import NodeRunSummary

from qualibrate_runner.config import State
from qualibrate_runner.core.models.last_run import (
LastRun,
Expand Down Expand Up @@ -103,9 +103,12 @@ def run_workflow(
try:
library = get_active_library_or_error()
workflow = library.graphs[workflow.name]
result = library.run_graph(
workflow.name,
workflow.full_parameters_class(**passed_input_parameters),
input_parameters = workflow.full_parameters_class(
**passed_input_parameters
)
result = workflow.run(
nodes=input_parameters.nodes.model_dump(),
**input_parameters.parameters.model_dump(),
)
print("Graph completed. Result:", result)
except Exception as ex:
Expand Down

0 comments on commit ff8bb40

Please sign in to comment.