Skip to content

Commit

Permalink
Make state change logic atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Oct 11, 2023
1 parent 1597d13 commit 385e855
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,9 +1550,10 @@ def change_state(self, state, info=False, flush=True, job=None):
return
if info:
job.info = info
job.set_state(state)
state_changed = job.set_state(state)
self.sa_session.add(job)
job.update_output_states(self.app.application_stack.supports_skip_locked())
if state_changed:
job.update_output_states(self.app.application_stack.supports_skip_locked())
if flush:
with transaction(self.sa_session):
self.sa_session.commit()
Expand Down
23 changes: 20 additions & 3 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,10 +1640,27 @@ def all_entry_points_configured(self):

def set_state(self, state):
"""
Save state history
Save state history. Returns True if stat has changed, else False
"""
self.state = state
self.state_history.append(JobStateHistory(self))
if self.state == state:
# Nothing changed, no action needed
return False
session = object_session(self)
if session and self.id and not state in Job.terminal_states:
# generate statement that will not revert DELETING or DELETED back to anything non-terminal
rval = session.execute(update(Job.table).where(
Job.table.c.id == self.id,
~Job.table.c.state.in_((Job.states.DELETING, Job.states.DELETED))
).values(state=state))
if rval.rowcount == 1:
self.state_history.append(JobStateHistory(self))
return True
else:
return False
else:
self.state = state
self.state_history.append(JobStateHistory(self))
return True

def get_param_values(self, app, ignore_errors=False):
"""
Expand Down

0 comments on commit 385e855

Please sign in to comment.