From b684ee96f2328eedf2c6c885453f8b48044a8683 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 13 Nov 2023 15:59:53 +0100 Subject: [PATCH] Add new finished_states and move deleting to that --- lib/galaxy/model/__init__.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index c2e201eb3f52..ac2abf82df32 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1367,7 +1367,10 @@ class Job(Base, JobLike, UsesCreateAndUpdateTime, Dictifiable, Serializable): states = JobState - terminal_states = [states.OK, states.ERROR, states.DELETED, states.DELETING] + # states that are not expected to change, except through admin action or re-scheduling + terminal_states = [states.OK, states.ERROR, states.DELETED] + # deleting state should not turn back into any of the non-ready states + finished_states = terminal_states + [states.DELETING] #: job states where the job hasn't finished and the model may still change non_ready_states = [ states.NEW, @@ -1392,13 +1395,7 @@ def running(self): @property def finished(self): - states = self.states - return self.state in [ - states.OK, - states.ERROR, - states.DELETING, - states.DELETED, - ] + return self.state in self.finished_states def io_dicts(self, exclude_implicit_outputs=False) -> IoDicts: inp_data: Dict[str, Optional[DatasetInstance]] = {da.name: da.dataset for da in self.input_datasets} @@ -1643,7 +1640,7 @@ def set_state(self, state: JobState) -> bool: # Nothing changed, no action needed return False session = object_session(self) - if session and self.id and state not in Job.terminal_states: + if session and self.id and state not in Job.finished_states: # generate statement that will not revert DELETING or DELETED back to anything non-terminal rval = session.execute( update(Job.table) @@ -8233,7 +8230,7 @@ def cancel_invocation_steps(self): sa_session.query(Job.id) .join(WorkflowInvocationStep) .filter(WorkflowInvocationStep.workflow_invocation_id == self.id) - .filter(~Job.table.c.state.in_(Job.terminal_states)) + .filter(~Job.table.c.state.in_(Job.finished_states)) .with_for_update() .scalar_subquery() ) @@ -8247,7 +8244,7 @@ def cancel_invocation_steps(self): WorkflowInvocationStep, WorkflowInvocationStep.implicit_collection_jobs_id == ImplicitCollectionJobs.id ) .filter(WorkflowInvocationStep.workflow_invocation_id == self.id) - .filter(~Job.table.c.state.in_(Job.terminal_states)) + .filter(~Job.table.c.state.in_(Job.finished_states)) .with_for_update() .subquery() )