Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cg/apps/tb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def add_pending_analysis(
self,
case_id: str,
analysis_type: str,
config_path: str,
config_path: str | None,
out_dir: str,
priority: TrailblazerPriority,
workflow: Workflow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def _workflow_manager(self):
def _get_job_ids_path(self, case_id: str) -> Path:
return Path(self.workflow_root, case_id, "analysis", "slurm_jobids.yaml")

def _get_out_dir_path(self, case_id: str) -> Path:
return self._get_job_ids_path(case_id).parent

def _get_workflow_version(self, case_config: BalsamicCaseConfig) -> str:
config_data: dict = read_json(case_config.sample_config)
return config_data["analysis"]["BALSAMIC_version"]
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def _get_job_ids_path(self, case_id: str) -> Path:
f"{project_id}_slurm_ids{FileExtensions.YAML}",
)

def _get_out_dir_path(self, case_id: str) -> Path:
return self._get_job_ids_path(case_id).parent

def _get_file_name_start(self, case_id: str) -> str:
"""Returns the LIMS project id if the case contains multiple samples, else the sample id."""
case: Case = self.store.get_case_by_internal_id(case_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def _workflow_manager(self) -> WorkflowManager:
def _get_job_ids_path(self, case_id: str) -> Path:
return Path(self.workflow_root, case_id, "analysis", "slurm_job_ids.yaml")

def _get_out_dir_path(self, case_id: str) -> Path:
return self._get_job_ids_path(case_id).parent

def _get_sample_info_path(self, case_id: str) -> Path:
return Path(self.workflow_root, case_id, "analysis", f"{case_id}_qc_sample_info.yaml")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from cg.constants.constants import FileExtensions, WorkflowManager
from cg.constants.constants import WorkflowManager
from cg.services.analysis_starter.configurator.models.nextflow import NextflowCaseConfig
from cg.services.analysis_starter.tracker.tracker import Tracker

Expand All @@ -9,9 +9,11 @@ class NextflowTracker(Tracker):
def _workflow_manager(self) -> WorkflowManager:
return WorkflowManager.Tower

def _get_job_ids_path(self, case_id: str) -> Path:
"""Return the path to a Trailblazer config file containing Tower IDs."""
return Path(self.workflow_root, case_id, "tower_ids").with_suffix(FileExtensions.YAML)
def _get_job_ids_path(self, case_id: str) -> Path | None:
return None

def _get_out_dir_path(self, case_id: str) -> Path:
return Path(self.workflow_root, case_id)

def _get_workflow_version(self, case_config: NextflowCaseConfig) -> str:
return case_config.revision
20 changes: 12 additions & 8 deletions cg/services/analysis_starter/tracker/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cg.apps.environ import environ_email
from cg.apps.tb import TrailblazerAPI
from cg.apps.tb.models import TrailblazerAnalysis
from cg.constants.constants import CaseActions, CustomerId, Workflow
from cg.constants.constants import CaseActions, CustomerId, Workflow, WorkflowManager
from cg.constants.priority import TrailblazerPriority
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.constants.tb import AnalysisType
Expand Down Expand Up @@ -62,25 +62,25 @@ def _track_in_trailblazer(
self, case_id: str, tower_workflow_id: int | None
) -> TrailblazerAnalysis:
analysis_type: str = self._get_analysis_type(case_id)
config_path: Path = self._get_job_ids_path(case_id)
config_path: Path | None = self._get_job_ids_path(case_id)
email: str = environ_email()
order_id: int = self.store.get_case_by_internal_id(case_id).latest_order.id
out_dir: str = config_path.parent.as_posix()
out_dir: Path = self._get_out_dir_path(case_id)
priority: TrailblazerPriority = self._get_trailblazer_priority(case_id)
ticket: str = self.store.get_latest_ticket_from_case(case_id)
is_case_for_development: bool = self._is_case_for_development(case_id)
return self.trailblazer_api.add_pending_analysis(
analysis_type=analysis_type,
case_id=case_id,
config_path=config_path.as_posix(),
config_path=config_path.as_posix() if config_path else None,
email=email,
order_id=order_id,
out_dir=out_dir,
out_dir=out_dir.as_posix(),
priority=priority,
ticket=ticket,
workflow=self.store.get_case_workflow(case_id),
workflow_manager=self._workflow_manager(),
tower_workflow_id=tower_workflow_id,
tower_workflow_id=str(tower_workflow_id) if tower_workflow_id else None,
is_hidden=is_case_for_development,
)

Expand Down Expand Up @@ -133,11 +133,15 @@ def _is_case_for_development(self, case_id: str) -> bool:
return case.customer.internal_id == CustomerId.CG_INTERNAL_CUSTOMER

@abstractmethod
def _workflow_manager(self):
def _workflow_manager(self) -> WorkflowManager:
pass

@abstractmethod
def _get_job_ids_path(self, case_id: str):
def _get_job_ids_path(self, case_id: str) -> Path | None:
pass

@abstractmethod
def _get_out_dir_path(self, case_id: str) -> Path:
pass

@abstractmethod
Expand Down
20 changes: 12 additions & 8 deletions tests/services/analysis_starter/test_nextflow_tracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pathlib import Path
from typing import cast

import mock
import pytest
Expand All @@ -7,7 +7,7 @@
from cg.apps.tb import TrailblazerAPI
from cg.constants.constants import Workflow, WorkflowManager
from cg.constants.tb import AnalysisType
from cg.models.cg_config import CGConfig
from cg.models.cg_config import CGConfig, RarediseaseConfig
from cg.models.orders.sample_base import StatusEnum
from cg.services.analysis_starter.configurator.models.nextflow import NextflowCaseConfig
from cg.services.analysis_starter.tracker.implementations.nextflow import NextflowTracker
Expand Down Expand Up @@ -35,13 +35,15 @@ def nextflow_tracker(cg_context: CGConfig, helpers: StoreHelpers, raredisease_ca
return NextflowTracker(
store=cg_context.status_db,
trailblazer_api=cg_context.trailblazer_api,
workflow_root=cg_context.raredisease.root,
workflow_root=cast(RarediseaseConfig, cg_context.raredisease).root,
)


def test_nextflow_tracker(nextflow_tracker: NextflowTracker, raredisease_case_id: str):
def test_nextflow_tracker(
cg_context: CGConfig, nextflow_tracker: NextflowTracker, raredisease_case_id: str
):
# GIVEN a raredisease case
case: Case = nextflow_tracker.store.get_case_by_internal_id(raredisease_case_id)
case: Case = cast(Case, nextflow_tracker.store.get_case_by_internal_id(raredisease_case_id))
case_config = NextflowCaseConfig(
case_id=raredisease_case_id,
workflow=Workflow.RAREDISEASE,
Expand All @@ -55,6 +57,9 @@ def test_nextflow_tracker(nextflow_tracker: NextflowTracker, raredisease_case_id
work_dir="work/dir",
)

# GIVEN a root directory is set
root_directory: str = cast(RarediseaseConfig, cg_context.raredisease).root

# WHEN wanting to track the started microSALT analysis
with mock.patch.object(
TrailblazerAPI,
Expand All @@ -71,14 +76,13 @@ def test_nextflow_tracker(nextflow_tracker: NextflowTracker, raredisease_case_id
nextflow_tracker.track(case_config=case_config, tower_workflow_id="1")

# THEN the appropriate POST should have been sent
config_path: Path = nextflow_tracker._get_job_ids_path(raredisease_case_id)
expected_request_body: dict = {
"case_id": raredisease_case_id,
"email": environ_email(),
"type": AnalysisType.WGS,
"config_path": config_path.as_posix(),
"config_path": None,
"order_id": case.latest_order.id,
"out_dir": config_path.parent.as_posix(),
"out_dir": f"{root_directory}/{raredisease_case_id}",
"priority": nextflow_tracker._get_trailblazer_priority(raredisease_case_id),
"workflow": Workflow.RAREDISEASE.upper(),
"ticket": str(case.latest_order.ticket_id),
Expand Down
Loading