Commit 162c8636 authored by Guido Trotter's avatar Guido Trotter
Browse files

Abstract loading job file from disk



Move the work from _LoadJobUnlocked to _LoadJobFileFromDisk, which can
then be used in other contexts as well. Also, if we fail to deserialize
the job, archive it as well (before we archived it only if we failed to
create the related object, but kept it there if deserialization failed.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 3baa809c
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment