Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
More update_status fixes (#322)
Browse files Browse the repository at this point in the history
Co-authored-by: Nickolas Comeau <[email protected]>
  • Loading branch information
Comeani and Comeani authored Aug 29, 2023
1 parent 31462e1 commit f4ccdd2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bank/account_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,28 +934,33 @@ def update_status(self) -> None:
exceeding_sus_total = sum(cluster["exceeding_sus"] for cluster in lock_clusters)

# Floating SUs can cover
if exceeding_sus_total <= floating_sus_remaining:
if floating_alloc and (exceeding_sus_total <= floating_sus_remaining):
floating_alloc.service_units_used += exceeding_sus_total
for cluster in lock_clusters:
cluster["alloc"].service_units_used = cluster["alloc"].service_units_total
LOG.debug(f"Using floating service units to cover usage over limit for {self._account_name} "
f"on {cluster['name']}")

# Investment SUs can cover
elif exceeding_sus_total - floating_sus_remaining <= investment_sus:
elif investment and (exceeding_sus_total - floating_sus_remaining <= investment_sus):
remaining_sus = exceeding_sus_total - floating_sus_remaining
if floating_alloc:
floating_alloc.service_units_used = floating_alloc.service_units_total
investment.current_sus -= remaining_sus

# TODO: do withdrawn SUs need to be changed?
for cluster in lock_clusters:
cluster["alloc"].service_units_used = cluster["alloc"].service_units_total
LOG.debug(f"Using investment service units to cover usage over limit for {self._account_name} "
f"on {cluster['name']}")

# Neither can cover
# TODO: this case should exhaust floating and investment service units as well
else:
if floating_alloc:
floating_alloc.service_units_used = floating_alloc.service_units_total
if investment:
investment.current_sus = 0

self.lock(clusters=cluster_names)
LOG.info(f"Locking {self._account_name} due to exceeding limits")

Expand Down

0 comments on commit f4ccdd2

Please sign in to comment.