Skip to content

Commit

Permalink
Raise exception when jobs are missing
Browse files Browse the repository at this point in the history
If no jobs are stored for an analysis, a status cannot be calculated for it.
  • Loading branch information
seallard committed May 13, 2024
1 parent 9e2501e commit 06f33fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions trailblazer/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class TrailblazerError(Exception):

class JobServiceError(TrailblazerError):
pass


class NoJobsError(JobServiceError):
pass
6 changes: 5 additions & 1 deletion trailblazer/services/job_service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from trailblazer.constants import TrailblazerStatus, WorkflowManager
from trailblazer.dto import CreateJobRequest, FailedJobsRequest, FailedJobsResponse, JobResponse
from trailblazer.exceptions import JobServiceError
from trailblazer.exceptions import JobServiceError, NoJobsError
from trailblazer.services.job_service.mappers import (
create_failed_jobs_response,
create_job_response,
Expand Down Expand Up @@ -60,6 +60,10 @@ def _update_slurm_jobs(self, analysis_id: int) -> None:

def get_analysis_status(self, analysis_id: int) -> TrailblazerStatus:
analysis: Analysis = self.store.get_analysis_with_id(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

0 comments on commit 06f33fe

Please sign in to comment.