handle refusal with an exception

This commit is contained in:
Mike McLean 2024-02-02 14:12:52 -05:00 committed by Tomas Kopecek
parent 4b35b7b729
commit 4a31c42edd
3 changed files with 12 additions and 3 deletions

View file

@ -79,7 +79,8 @@ from koji.tasks import (
BaseTaskHandler,
MultiPlatformTask,
ServerExit,
ServerRestart
ServerRestart,
RefuseTask,
)
from koji.util import (
dslice,
@ -5731,7 +5732,7 @@ class NewRepoTask(BaseTaskHandler):
if not os.path.isdir(top_repos_dir):
# missing or incorrect mount?
# refuse and let another host try
self.session.host.refuseTask(self.id, msg="No access to repos dir %s" % top_repos_dir)
raise RefuseTask("No access to repos dir %s" % top_repos_dir)
# call repoInit
kwargs = {}
@ -5841,7 +5842,7 @@ class CreaterepoTask(BaseTaskHandler):
if not os.path.isdir(top_repos_dir):
# missing or incorrect mount?
# refuse and let another host try
self.session.host.refuseTask(self.id, msg="No access to repos dir %s" % top_repos_dir)
raise RefuseTask("No access to repos dir %s" % top_repos_dir)
else:
# we seem to have fs access, but dir is missing, perhaps a repo_init bug?
raise koji.GenericError("Repo directory missing: %s" % self.repodir)

View file

@ -1504,6 +1504,9 @@ class TaskManager(object):
except (SystemExit, koji.tasks.ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except koji.tasks.RefuseTask as refuse:
self.session.host.refuseTask(handler.id, msg=str(refuse))
return
except koji.tasks.ServerRestart:
# freeing this task will allow the pending restart to take effect
self.session.host.freeTasks([handler.id])

View file

@ -110,6 +110,11 @@ class ServerRestart(Exception):
pass
class RefuseTask(Exception):
"""Raise to task handler to refuse a task"""
pass
def parse_task_params(method, params):
"""Parse task params into a dictionary