Skip to content

Commit

Permalink
Adding sorting for runs state otherwise runs will be out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanElsaban committed Apr 19, 2024
1 parent f4cd57e commit b021c6d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tron/serialize/runstate/statemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from tron.serialize.runstate.yamlstore import YamlStateStore
from tron.utils import observer

# import threading

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -139,7 +137,6 @@ def __init__(self, persistence_impl, buffer):
self.enabled = True
self._buffer = buffer
self._impl = persistence_impl
# self._lock = threading.Lock()
self.metadata_key = self._impl.build_key(
runstate.MCP_STATE,
StateMetadata.name,
Expand Down Expand Up @@ -178,16 +175,17 @@ def restore(self, job_names, skip_validation=False):
def _restore_runs_for_job(self, job_name, job_state):
"""Restore the state for the runs of each job"""
run_nums = job_state["run_nums"]
# with self._lock:
keys = [jobrun.get_job_run_id(job_name, run_num) for run_num in run_nums]

job_runs_restored_states = self._restore_dicts(runstate.JOB_RUN_STATE, keys)
run_state = copy.copy(job_runs_restored_states)
for key, value in run_state.items():
if value == {}:
log.error(f"Failed to restore {key}, no state found for it!")
job_runs_restored_states.pop(key)

run_state = list(job_runs_restored_states.values())
# We need to sort below otherwise the runs will not be in order
run_state.sort(key=lambda x: x["run_num"], reverse=True)
return run_state

def _restore_metadata(self):
Expand Down

0 comments on commit b021c6d

Please sign in to comment.