Skip to content

Commit a44ec98

Browse files
committed
More granular try-except blocks
1 parent 6bda176 commit a44ec98

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/murfey/server/api/__init__.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,31 +1616,36 @@ def remove_session_by_id(session_id: MurfeySessionID, db=murfey_db):
16161616
sessions_for_visit = db.exec(
16171617
select(Session).where(Session.visit == session.visit)
16181618
).all()
1619-
collected_ids = db.exec(
1620-
select(DataCollectionGroup, DataCollection, ProcessingJob)
1621-
.where(DataCollectionGroup.session_id == session_id)
1622-
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1623-
.where(ProcessingJob.dc_id == DataCollection.id)
1624-
).all()
1625-
# Ignore key errors when deleting Prometheus entries (it might not be set up)
1626-
try:
1627-
# Don't remove prometheus metrics if there are other sessions using them
1628-
if len(sessions_for_visit) == 1:
1629-
rsync_instances = db.exec(
1630-
select(RsyncInstance).where(RsyncInstance.session_id == session_id)
1631-
).all()
1619+
# Don't remove prometheus metrics if there are other sessions using them
1620+
if len(sessions_for_visit) == 1:
1621+
try:
16321622
prom.monitoring_switch.remove(session.visit)
1633-
for ri in rsync_instances:
1623+
except KeyError:
1624+
pass
1625+
rsync_instances = db.exec(
1626+
select(RsyncInstance).where(RsyncInstance.session_id == session_id)
1627+
).all()
1628+
for ri in rsync_instances:
1629+
try:
16341630
prom.seen_files.remove(ri.source, session.visit)
16351631
prom.transferred_files.remove(ri.source, session.visit)
16361632
prom.transferred_files_bytes.remove(ri.source, session.visit)
16371633
prom.seen_data_files.remove(ri.source, session.visit)
16381634
prom.transferred_data_files.remove(ri.source, session.visit)
16391635
prom.transferred_data_files_bytes.remove(ri.source, session.visit)
1640-
for c in collected_ids:
1636+
except KeyError:
1637+
pass
1638+
collected_ids = db.exec(
1639+
select(DataCollectionGroup, DataCollection, ProcessingJob)
1640+
.where(DataCollectionGroup.session_id == session_id)
1641+
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1642+
.where(ProcessingJob.dc_id == DataCollection.id)
1643+
).all()
1644+
for c in collected_ids:
1645+
try:
16411646
prom.preprocessed_movies.remove(c[2].id)
1642-
except KeyError:
1643-
pass
1647+
except KeyError:
1648+
continue
16441649
db.delete(session)
16451650
db.commit()
16461651
return

0 commit comments

Comments
 (0)