Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch pending tower analyses #506

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions tests/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,25 @@ def analysis_without_jobs(analysis_store: Store):
@pytest.fixture
def analysis_service(analysis_store: Store, job_service_mock: JobService) -> AnalysisService:
return AnalysisService(store=analysis_store, job_service=job_service_mock)

@pytest.fixture
def tower_analysis_without_jobs_and_pending(analysis_store: Store):
analysis = Analysis(
config_path="config_path",
workflow="workflow",
case_id="case_id",
out_dir="out_dir",
priority=PRIORITY_OPTIONS[0],
started_at=datetime.now() - timedelta(weeks=1),
status=TrailblazerStatus.PENDING,
ticket_id="ticket_id",
type=TYPES[0],
workflow_manager=WorkflowManager.TOWER,
is_visible=True,
order_id=1,
)
session: Session = get_session()
session.add(analysis)
session.commit()
return analysis

34 changes: 33 additions & 1 deletion tests/services/test_job_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from trailblazer.constants import TrailblazerStatus
from unittest import mock

import pytest

from trailblazer.clients.tower.models import TowerWorkflowResponse
from trailblazer.constants import TrailblazerStatus, TowerStatus
from trailblazer.exceptions import NoJobsError
from trailblazer.services.job_service import JobService
from trailblazer.store.models import Analysis

Expand Down Expand Up @@ -57,3 +63,29 @@ def test_analysis_status_when_running_jobs(

# THEN the status is running
assert status == TrailblazerStatus.RUNNING


def test_tower_analysis_status_pending_no_jobs(
job_service: JobService,
tower_analysis_without_jobs_and_pending: Analysis,
tower_workflow_response: TowerWorkflowResponse,
):
# GIVEN a Tower analysis with no jobs and a SUBMITTED status
job_service.tower_service.client.get_workflow.return_value = tower_workflow_response

# Simulate a SUBMITTED workflow status from Tower
tower_workflow_response.workflow.status = TowerStatus.SUBMITTED

# WHEN fetching the analysis status
status = job_service.get_analysis_status(tower_analysis_without_jobs_and_pending.id)

# THEN the analysis status should be PENDING
assert status == TrailblazerStatus.PENDING


def test_no_jobs_error_for_slurm_analysis(job_service: JobService, analysis_without_jobs: Analysis):
# GIVEN an analysis without any associated jobs
# WHEN fetching the analysis status
# THEN a NoJobsError should be raised
with pytest.raises(NoJobsError):
job_service.get_analysis_status(analysis_without_jobs.id)
35 changes: 25 additions & 10 deletions trailblazer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TrailblazerStatus(StrEnum):
PENDING: str = "pending"
QC: str = "qc"
RUNNING: str = "running"
SUBMITTED: str = "submitted"

@classmethod
def statuses(cls) -> tuple:
Expand All @@ -137,18 +138,32 @@ class TrailblazerStatusColor(StrEnum):
PENDING: str = "yellow"
RUNNING: str = "blue"

class TowerStatus(StrEnum):
"""Tower statuses"""

ABORTED: str = "ABORTED"
CACHED: str = "CACHED"
CANCELLED: str = "CANCELLED"
COMPLETED: str = "COMPLETED"
FAILED: str = "FAILED"
NEW: str = "NEW"
RUNNING: str = "RUNNING"
SUBMITTED: str = "SUBMITTED"
SUCCEEDED: str = "SUCCEEDED"
UNKNOWN: str = "UNKNOWN"


TOWER_WORKFLOW_STATUS: dict[str, str] = {
"ABORTED": TrailblazerStatus.FAILED,
"CACHED": TrailblazerStatus.COMPLETED,
"CANCELLED": TrailblazerStatus.CANCELLED,
"COMPLETED": TrailblazerStatus.COMPLETED,
"FAILED": TrailblazerStatus.FAILED,
"NEW": TrailblazerStatus.PENDING,
"RUNNING": TrailblazerStatus.RUNNING,
"SUBMITTED": TrailblazerStatus.PENDING,
"SUCCEEDED": TrailblazerStatus.COMPLETED,
"UNKNOWN": TrailblazerStatus.FAILED,
TowerStatus.ABORTED : TrailblazerStatus.FAILED,
TowerStatus.CACHED : TrailblazerStatus.COMPLETED,
TowerStatus.CANCELLED : TrailblazerStatus.CANCELLED,
TowerStatus.COMPLETED : TrailblazerStatus.COMPLETED,
TowerStatus.FAILED : TrailblazerStatus.FAILED,
TowerStatus.NEW : TrailblazerStatus.PENDING,
TowerStatus.RUNNING : TrailblazerStatus.RUNNING,
TowerStatus.SUBMITTED : TrailblazerStatus.PENDING,
TowerStatus.SUCCEEDED : TrailblazerStatus.COMPLETED,
TowerStatus.UNKNOWN : TrailblazerStatus.FAILED,
}


Expand Down
6 changes: 3 additions & 3 deletions trailblazer/services/job_service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def get_analysis_status(self, analysis_id: int) -> TrailblazerStatus:
if analysis.status == TrailblazerStatus.CANCELLED:
return TrailblazerStatus.CANCELLED

if not analysis.jobs:
raise NoJobsError(f"No jobs found for analysis {analysis_id}")

if analysis.workflow_manager == WorkflowManager.TOWER:
return self.tower_service.get_status(analysis_id)

if not analysis.jobs:
raise NoJobsError(f"No jobs found for analysis {analysis_id}")

return get_status(analysis.jobs)

def get_analysis_progression(self, analysis_id: int) -> float:
Expand Down
Loading