From 70dad74331242aa846f71259c12d4cc926711445 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 4 Jul 2024 13:16:05 +0200 Subject: [PATCH] Don't call job_runner.stop_job on jobs in new state These aren't submitted yet, no point in doing that. Fixes https://sentry.galaxyproject.org/share/issue/ea06518238f1409eb22a8f502f9db557/: ``` AssertionError: External job id is None File "galaxy/jobs/runners/drmaa.py", line 375, in stop_job assert ext_id not in (None, "None"), "External job id is None" ``` --- lib/galaxy/jobs/handler.py | 3 ++- lib/galaxy/jobs/runners/__init__.py | 3 ++- lib/galaxy/jobs/runners/aws.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/jobs/handler.py b/lib/galaxy/jobs/handler.py index 0213a797aab4..91d5b8b36a50 100644 --- a/lib/galaxy/jobs/handler.py +++ b/lib/galaxy/jobs/handler.py @@ -1260,7 +1260,8 @@ def stop(self, job, job_wrapper): runner_name = job_runner_name.split(":", 1)[0] log.debug(f"Stopping job {job_wrapper.get_id_tag()} in {runner_name} runner") try: - self.job_runners[runner_name].stop_job(job_wrapper) + if not job.state == model.Job.states.NEW: + self.job_runners[runner_name].stop_job(job_wrapper) except KeyError: log.error(f"stop(): ({job_wrapper.get_id_tag()}) Invalid job runner: {runner_name}") # Job and output dataset states have already been updated, so nothing is done here. diff --git a/lib/galaxy/jobs/runners/__init__.py b/lib/galaxy/jobs/runners/__init__.py index bde5baedeb08..640372e7d290 100644 --- a/lib/galaxy/jobs/runners/__init__.py +++ b/lib/galaxy/jobs/runners/__init__.py @@ -581,7 +581,8 @@ def _handle_runner_state(self, runner_state, job_state: "JobState"): log.exception("Caught exception in runner state handler") def fail_job(self, job_state: "JobState", exception=False, message="Job failed", full_status=None): - if getattr(job_state, "stop_job", True): + job = job_state.job_wrapper.get_job() + if getattr(job_state, "stop_job", True) and job.state != model.Job.states.NEW: self.stop_job(job_state.job_wrapper) job_state.job_wrapper.reclaim_ownership() self._handle_runner_state("failure", job_state) diff --git a/lib/galaxy/jobs/runners/aws.py b/lib/galaxy/jobs/runners/aws.py index 5f301b078975..bd512f401a9d 100644 --- a/lib/galaxy/jobs/runners/aws.py +++ b/lib/galaxy/jobs/runners/aws.py @@ -418,7 +418,8 @@ def recover(self, job, job_wrapper): self.monitor_queue.put(ajs) def fail_job(self, job_state, exception=False): - if getattr(job_state, "stop_job", True): + job = job_state.job_wrapper.get_job() + if getattr(job_state, "stop_job", True) and job.state != model.Job.states.NEW: self.stop_job(job_state.job_wrapper) job_state.job_wrapper.reclaim_ownership() self._handle_runner_state("failure", job_state)