Skip to content

Commit

Permalink
Allow going backwards in state, but not if in a COMPLETED or FAILED s…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
nmassey001 committed Oct 22, 2024
1 parent 05d1700 commit 26369b5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions nlds_processors/monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ def get_sub_records(

return srecs

def update_sub_record(
self, sub_record: SubRecord, new_state: State
) -> SubRecord:
def update_sub_record(self, sub_record: SubRecord, new_state: State) -> SubRecord:
"""Update a retrieved SubRecord to reflect the new monitoring info.
Furthest state is updated, if required.
"""
# Upgrade state to new_state, but throw exception if regressing state
# (staying the same is fine)
if new_state.value < sub_record.state.value:
# from COMPLETE or FAILED to a state below that
if (
sub_record.state.value >= State.COMPLETE.value
and new_state.value < State.COMPLETE.value
):
raise MonitorError(
f"Monitoring state cannot go backwards or skip steps. Attempted"
f" {sub_record.state}->{new_state}"
f"Monitoring state cannot go backwards from {sub_record.state}. "
f"Attempted {sub_record.state}->{new_state}"
)
sub_record.state = new_state
self.session.flush()
Expand Down

0 comments on commit 26369b5

Please sign in to comment.