From aebd0e4e7ff5aa0e1c4d9cbac0e80b27119fbc24 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 24 Oct 2012 03:19:20 +0200 Subject: [PATCH] jqueue: Factorize code to modify job A new function will be added to change a job's priority. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Bernardo Dal Seno <bdalseno@google.com> --- lib/jqueue.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/jqueue.py b/lib/jqueue.py index e6a279797..165cfec83 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -2309,15 +2309,27 @@ class JobQueue(object): """ logging.info("Cancelling job %s", job_id) + return self._ModifyJobUnlocked(job_id, lambda job: job.Cancel()) + + def _ModifyJobUnlocked(self, job_id, mod_fn): + """Modifies a job. + + @type job_id: int + @param job_id: Job ID + @type mod_fn: callable + @param mod_fn: Modifying function, receiving job object as parameter, + returning tuple of (status boolean, message string) + + """ job = self._LoadJobUnlocked(job_id) if not job: logging.debug("Job %s not found", job_id) return (False, "Job %s not found" % job_id) - assert job.writable, "Can't cancel read-only job" - assert not job.archived, "Can't cancel archived job" + assert job.writable, "Can't modify read-only job" + assert not job.archived, "Can't modify archived job" - (success, msg) = job.Cancel() + (success, msg) = mod_fn(job) if success: # If the job was finalized (e.g. cancelled), this is the final write -- GitLab