streamline hub calls

This commit is contained in:
Mike McLean 2024-03-04 15:38:43 -05:00 committed by Tomas Kopecek
parent fbb24d631d
commit f8c633f310
3 changed files with 33 additions and 14 deletions

View file

@ -1039,8 +1039,7 @@ class TaskManager(object):
def getNextTask(self):
self.ready = self.readyForTask()
self.session.host.updateHost(self.task_load, self.ready)
self.session.host.setHostData(json.dumps(self._get_host_data()))
self.session.host.updateHost(self.task_load, self.ready, data=self._get_host_data())
if not self.ready:
self.logger.info("Not ready for task")
return False

View file

@ -14704,10 +14704,19 @@ class HostExports(object):
host.verify()
return host.id
def updateHost(self, task_load, ready):
def updateHost(self, task_load, ready, data=None):
"""Update host data
:param float task_load: current task load
:param bool ready: whether the host is ready to take a task
:param dict data: data for the scheduler
"""
host = Host()
host.verify()
host.updateHost(task_load, ready)
if data is not None:
scheduler.set_host_data(host.id, data)
def getLoadData(self):
host = Host()
@ -14761,21 +14770,21 @@ class HostExports(object):
return task.setWeight(weight)
def setHostData(self, hostdata):
"""Builder will update all its resources
"""Provide host data for the scheduler
Initial implementation contains:
- available task methods
- maxjobs
- host readiness
:param dict hostdata: host data
For backwards compatibility, we also accept hostdata as a string containing a
json-encoded dictionary.
"""
host = Host()
host.verify()
upsert = UpsertProcessor(
table='scheduler_host_data',
keys=['host_id'],
data={'host_id': host.id, 'data': hostdata},
)
upsert.execute()
if isinstance(hostdata, str):
# for backwards compatibility
data = json.loads(hostdata)
else:
data = hostdata
scheduler.set_host_data(host.id, hostdata)
def getTasks(self):
host = Host()

View file

@ -153,6 +153,17 @@ def get_host_data(hostID=None):
return query.execute()
def set_host_data(hostID, data):
if not isinstance(data, dict):
raise koji.ParameterError('Host data should be a dictionary')
upsert = UpsertProcessor(
table='scheduler_host_data',
keys=['host_id'],
data={'host_id': hostID, 'data': json.dumps(data)},
)
upsert.execute()
class TaskRunsQuery(QueryView):
tables = ['scheduler_task_runs']