From c609f8025686c7d88678dcb47cadb033848b8ab1 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 24 Jul 2008 11:32:58 +0000 Subject: [PATCH] Implement job archiving on the server side So far no error reporting to the client is done. Clients don't get noticed if a job doesn't exist or couldn't be archived because of its current status. The internal cache is always cleaned when the preconditions didn't fail to make sure that the actual disk status will be reread next time. Reviewed-by: iustinp --- lib/jqueue.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/jqueue.py b/lib/jqueue.py index ed81ff784..4d31b8390 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -292,6 +292,14 @@ class JobStorageBase(object): return "%s%010d" % (prefix, job_id) + def _ShouldJobBeArchivedUnlocked(self, job): + if job.GetStatus() not in (constants.JOB_STATUS_CANCELED, + constants.JOB_STATUS_SUCCESS, + constants.JOB_STATUS_ERROR): + logging.debug("Job %s is not yet done", job.id) + return False + return True + class DiskJobStorage(JobStorageBase): _RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE) @@ -538,8 +546,35 @@ class DiskJobStorage(JobStorageBase): def UpdateJob(self, job): return self._UpdateJobUnlocked(job) + @utils.LockedMethod def ArchiveJob(self, job_id): - raise NotImplementedError() + """Archives a job. + + @type job_id: string + @param job_id: Job ID of job to be archived. + + """ + logging.debug("Archiving job %s", job_id) + + job = self._LoadJobUnlocked(job_id) + if not job: + logging.debug("Job %s not found", job_id) + return + + if not self._ShouldJobBeArchivedUnlocked(job): + return + + try: + old = self._GetJobPath(job.id) + new = self._GetArchivedJobPath(job.id) + + os.rename(old, new) + + logging.debug("Successfully archived job %s", job.id) + finally: + # Cleaning the cache because we don't know what os.rename actually did + # and to be on the safe side. + self._CleanCacheUnlocked([]) class JobQueue: @@ -582,7 +617,7 @@ class JobQueue: return job.id def ArchiveJob(self, job_id): - raise NotImplementedError() + self._jobs.ArchiveJob(job_id) def CancelJob(self, job_id): raise NotImplementedError() -- GitLab