Skip to content

Commit

Permalink
adjust logging
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Aug 13, 2024
1 parent c60f5d6 commit f397d27
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions coldfront/plugins/sftocf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,20 @@ def generate_headers(token):

class AllocationQueryMatch:
"""class to hold Allocations and related query results together."""
def __new__(cls, allocation, total_usage_entries, user_usage_entries):
def __new__(cls, allocation, total_usage_entries, user_usage_entries, usage=False):
allocation_data = (
allocation.pk, allocation.project.title, allocation.resources.first()
)
msg = None
if not total_usage_entries:
msg = f'No starfish allocation usage result for allocation {allocation_data}; deactivation suggested'
elif len(total_usage_entries) > 1:
msg = f'too many total_usage_entries for allocation {allocation_data}; investigation required'
if msg:
print(msg)
logger.warning(msg)
return None
if usage:
if not total_usage_entries:
msg = f'No starfish allocation usage result for allocation {allocation_data}; deactivation suggested'
elif len(total_usage_entries) > 1:
msg = f'too many total_usage_entries for allocation {allocation_data}; investigation required'
if msg:
print(msg)
logger.warning(msg)
return None
return super().__new__(cls)

def __init__(self, allocation, total_usage_entries, user_usage_entries):
Expand Down Expand Up @@ -631,7 +632,7 @@ def allocationquerymatches(self, usage=False):
total_usage_entries = allocation_usage_grouped.get(a, None)
user_usage_entries = user_usage_grouped.get(a, [])
allocationquerymatch_objs.append(
AllocationQueryMatch(allocation, total_usage_entries, user_usage_entries)
AllocationQueryMatch(allocation, total_usage_entries, user_usage_entries, usage=usage)
)
self._allocationquerymatches = [a for a in allocationquerymatch_objs if a]
return self._allocationquerymatches
Expand Down Expand Up @@ -662,7 +663,7 @@ def clean_collected_data(self):
obj.user_usage_entries.remove(i)
return self.allocationquerymatches, user_models

def update_coldfront_allocation_usage(self):
def update_coldfront_allocation_usage(self, obj):
"""update coldfront allocation usage"""
allocation_attribute_types = AllocationAttributeType.objects.all()
quota_b_attrtype = allocation_attribute_types.get(name='Quota_In_Bytes')
Expand All @@ -677,9 +678,9 @@ def update_coldfront_allocation_usage(self):

def update_coldfront_objects(self, user_models, usage=False):
"""update coldfront allocation objects"""
if usage:
self.update_coldfront_allocation_usage()
# 3. iterate across allocations
if usage:
self.update_coldfront_allocation_usage(obj)
for obj in self.allocationquerymatches(usage=usage):
logger.debug('updating allocation %s %s (path %s)',
obj.lab, obj.volume, obj.allocation.path
Expand Down

0 comments on commit f397d27

Please sign in to comment.