Skip to content

Commit

Permalink
Allow setting priority for resubmitted tasks
Browse files Browse the repository at this point in the history
Set a given priority for a resubmitted task. If it's not specified,
the same priority as the original task will be used.
  • Loading branch information
emilyzheng committed Jan 11, 2021
1 parent 60d17ff commit bd74baa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion kobo/client/commands/cmd_resubmit_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def options(self):
self.parser.usage = "%%prog %s task_id [task_id...]" % self.normalized_name
self.parser.add_option("--force", action="store_true", help="Resubmit also tasks which are closed properly.")
self.parser.add_option("--nowait", default=False, action="store_true", help="Don't wait until tasks finish.")
self.parser.add_option("--priority", help="priority")


def run(self, *args, **kwargs):
Expand All @@ -25,6 +26,8 @@ def run(self, *args, **kwargs):

username = kwargs.pop("username", None)
password = kwargs.pop("password", None)
force = kwargs.pop("force", False)
priority = kwargs.pop("priority", None)

tasks = args

Expand All @@ -33,7 +36,7 @@ def run(self, *args, **kwargs):
failed = False
for task_id in tasks:
try:
resubmitted_id = self.hub.client.resubmit_task(task_id, kwargs.pop("force", False))
resubmitted_id = self.hub.client.resubmit_task(task_id, force, priority)
resubmitted_tasks.append(resubmitted_id)
except Exception as ex:
failed = True
Expand Down
3 changes: 2 additions & 1 deletion kobo/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def is_failed(self):
"""Is the task successfuly finished? Task state must be closed."""
return self.state in FAILED_STATES

def resubmit_task(self, user, force=False):
def resubmit_task(self, user, force=False, priority=None):
"""Resubmit failed/canceled top-level task."""
if not user.is_superuser:
if self.owner.username != user.username:
Expand All @@ -920,6 +920,7 @@ def resubmit_task(self, user, force=False):
"arch_name": self.arch.name,
"channel_name": self.channel.name,
"priority": self.priority,
"priority": priority if priority else self.priority,
"weight": self.weight,
"exclusive": self.exclusive,
"resubmitted_by": user,
Expand Down
4 changes: 2 additions & 2 deletions kobo/hub/xmlrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def cancel_task(request, task_id):


@login_required
def resubmit_task(request, task_id, force=False):
def resubmit_task(request, task_id, force=False, priority=None):
"""Resubmit a failed task and return new task_id."""
task = models.Task.objects.get(id=task_id)
return task.resubmit_task(request.user, force)
return task.resubmit_task(request.user, force, priority)


def list_workers(request, enabled=True):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_xmlrpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def test_resubmit_task(self):
new_id = client.resubmit_task(_make_request(self._user), task_id, force=False)
self.assertTrue(new_id > 0)
self.assertNotEqual(task_id, new_id)
task = Task.objects.get(id=new_id)
self.assertEqual(task.priority, 10)

def test_resubmit_task_do_not_failed(self):
task_id = Task.create_task(self._user.username, 'task', 'method', state=TASK_STATES['OPEN'])
Expand All @@ -223,6 +225,12 @@ def test_resubmit_task_non_existent(self):
with self.assertRaises(Task.DoesNotExist):
client.resubmit_task(_make_request(), 999)

def test_resubmit_task_set_priority(self):
task_id = Task.create_task(self._user.username, 'task', 'method', state=TASK_STATES['TIMEOUT'])
new_id = client.resubmit_task(_make_request(self._user), task_id, force=False, priority=19)
task = Task.objects.get(id=new_id)
self.assertEqual(task.priority, 19)

def test_list_workers_enabled(self):
Worker.objects.create(
worker_key='enabled-worker',
Expand Down

0 comments on commit bd74baa

Please sign in to comment.