Skip to content

Commit

Permalink
Merge pull request #237 from lzaoral/hub-respect-worker-arches
Browse files Browse the repository at this point in the history
hub: do not assign tasks to workers with incompatible arches
  • Loading branch information
rohanpm authored Dec 12, 2023
2 parents 86ee235 + d4c514b commit a470ecf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kobo/hub/xmlrpc/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_tasks_to_assign(request):
return task_list

# awaited tasks
for task in Task.objects.free().filter(awaited=True).order_by("-priority", "id")[:max_tasks]:
for task in Task.objects.free().filter(awaited=True, arch__in=request.worker.arches.all()).order_by("-priority", "id")[:max_tasks]:
task_info = task.export(flat=False)
task_list.append(task_info)

Expand All @@ -210,7 +210,7 @@ def get_tasks_to_assign(request):
# free tasks for each channel relevant to the worker
tasks = []
for channel in request.worker.channels.all():
for task in Task.objects.free().filter(awaited=False, channel=channel, priority__gte=request.worker.min_priority).order_by("-priority", "id")[:max_tasks]:
for task in Task.objects.free().filter(awaited=False, channel=channel, arch__in=request.worker.arches.all(), priority__gte=request.worker.min_priority).order_by("-priority", "id")[:max_tasks]:
task_info = task.export(flat=False)
tasks.append(task_info)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_xmlrpc_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,8 @@ def test_update_worker(self):
self.assertEqual(wi['task_count'], 1)

def test_get_tasks_to_assign(self):
new_arch = Arch.objects.create(name='testarch2', pretty_name='testarch2')

for _ in range(2):
Task.objects.create(
worker=self._worker,
Expand Down Expand Up @@ -790,6 +792,13 @@ def test_get_tasks_to_assign(self):
state=TASK_STATES['CLOSED'],
)

# task with an incompatible architecture
Task.objects.create(
arch=new_arch,
channel=self._channel,
owner=self._user,
)

req = _make_request(self._worker)
tasks = worker.get_tasks_to_assign(req)

Expand Down

0 comments on commit a470ecf

Please sign in to comment.