Skip to content

Commit

Permalink
Add try/except around submit() to handle failures
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Sep 28, 2023
1 parent 71509b0 commit 8b915b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/omero_demo_cleanup/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,24 @@ def resource_usage(
for user_id, user_name in users.items():
print(f'Finding disk usage of "{user_name}" (#{user_id}).')
user = {"Experimenter": [user_id]}
rsp = submit(conn, DiskUsage2(targetObjects=user), DiskUsage2Response)

file_count = 0
file_size = 0

for who, usage in rsp.totalFileCount.items():
if who.first == user_id:
file_count += usage
for who, usage in rsp.totalBytesUsed.items():
if who.first == user_id:
file_size += usage
try:
rsp = submit(conn, DiskUsage2(targetObjects=user), DiskUsage2Response)

for who, usage in rsp.totalFileCount.items():
if who.first == user_id:
file_count += usage
for who, usage in rsp.totalBytesUsed.items():
if who.first == user_id:
file_size += usage
except Exception:
print(f'FAILED to count data for "{user_name}" (#{user_id}).')

if file_count > 0 or file_size > 0:
user_stats.append(
UserStats(user_id, user_name, file_count, file_size, logouts[user_id])
UserStats(user_id, user_name, file_count, file_size, logouts.get(user_id, 0))
)
return user_stats

Expand Down

0 comments on commit 8b915b1

Please sign in to comment.