diff --git a/lib/jqueue.py b/lib/jqueue.py index 2554c7cc47fe920e07cf827c8c51159fa6c4964b..725d93bbdd0444fd394eb199f434143305812123 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -938,18 +938,34 @@ class JobQueue(object): logging.debug("Found job %s in memcache", job_id) return job + job = self._LoadJobFromDisk(job_id) + + self._memcache[job_id] = job + logging.debug("Added job %s to the cache", job_id) + return job + + def _LoadJobFromDisk(self, job_id): + """Load the given job file from disk. + + Given a job file, read, load and restore it in a _QueuedJob format. + + @type job_id: string + @param job_id: job identifier + @rtype: L{_QueuedJob} or None + @return: either None or the job object + + """ filepath = self._GetJobPath(job_id) logging.debug("Loading job from %s", filepath) try: raw_data = utils.ReadFile(filepath) - except IOError, err: + except EnvironmentError, err: if err.errno in (errno.ENOENT, ): return None raise - data = serializer.LoadJson(raw_data) - try: + data = serializer.LoadJson(raw_data) job = _QueuedJob.Restore(self, data) except Exception, err: # pylint: disable-msg=W0703 new_path = self._GetArchivedJobPath(job_id) @@ -962,8 +978,6 @@ class JobQueue(object): self._RenameFilesUnlocked([(filepath, new_path)]) return None - self._memcache[job_id] = job - logging.debug("Added job %s to the cache", job_id) return job def _GetJobsUnlocked(self, job_ids):