Skip to content

Commit

Permalink
Add new finished_states and move deleting to that
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Nov 14, 2023
1 parent 6cde33f commit db9d5b5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
)
Expand All @@ -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()
)
Expand Down

0 comments on commit db9d5b5

Please sign in to comment.