calcuate consumed capacity in same way in metrics

We should be consistent about this. Also this takes us from doing a as
many queries to the UnifiedJob table as we have instances to doing 1
query to the UnifiedJob table (and both do 1 query to Instances table)
This commit is contained in:
Elijah DeLee
2022-08-26 11:40:36 -04:00
parent 4fbf5e9e2f
commit 99815f8962
2 changed files with 20 additions and 19 deletions

View File

@@ -34,14 +34,14 @@ class TaskManagerInstance:
class TaskManagerInstances:
def __init__(self, active_tasks, instances=None):
def __init__(self, active_tasks, instances=None, instance_fields=['node_type', 'capacity', 'hostname', 'enabled']):
self.instances_by_hostname = dict()
self.instance_objects = []
if instances is None:
instances = (
Instance.objects.filter(hostname__isnull=False, enabled=True).exclude(node_type='hop').only('node_type', 'capacity', 'hostname', 'enabled')
)
instances = Instance.objects.filter(hostname__isnull=False, enabled=True).exclude(node_type='hop').only(*instance_fields)
for instance in instances:
self.instances_by_hostname[instance.hostname] = TaskManagerInstance(instance)
self.instance_objects.append(instance)
# initialize remaining capacity based on currently waiting and running tasks
for task in active_tasks: