Skip to content

Commit f803ba7

Browse files
committed
Upsert the job if slurm resets
1 parent f2ff812 commit f803ba7

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

biomero/views.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ def _(self, domain_event, process_event):
101101

102102
@retry_on_database_conflict(max_retries=3)
103103
def update_view_table(self, job_id, user, group, task_id):
104-
"""Update the view table with new job information."""
104+
"""Update the view table with new job information.
105+
106+
Uses merge (upsert) so that if SLURM recycles a job ID the new
107+
task_id/user/group overwrites the stale row instead of silently
108+
failing and leaving the old mapping in place.
109+
"""
105110
with EngineManager.get_session() as session:
106111
try:
107112
new_job = JobView(slurm_job_id=job_id, user=user, group=group, task_id=task_id)
108-
session.add(new_job)
113+
session.merge(new_job)
109114
session.commit()
110-
logger.debug(f"Inserted job into view table: job_id={job_id}, user={user}, group={group}, task_id={task_id}")
115+
logger.debug(f"Upserted job into view table: job_id={job_id}, user={user}, group={group}, task_id={task_id}")
111116
except IntegrityError as e:
112117
session.rollback()
113-
# Handle the case where the job already exists in the table if necessary
114-
logger.warning(f"Database conflict inserting job (will retry): job_id={job_id}, user={user}, group={group}, error={e}")
118+
logger.warning(f"Database conflict upserting job (will retry): job_id={job_id}, user={user}, group={group}, error={e}")
119+
raise
115120

116121
def get_jobs(self, user=None, group=None):
117122
"""Retrieve jobs for a specific user and/or group.

0 commit comments

Comments
 (0)