Commit c609f802 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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

Reviewed-by: iustinp
parent 0cb94105
......@@ -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,
logging.debug("Job %s is not yet done",
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)
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)
if not self._ShouldJobBeArchivedUnlocked(job):
old = self._GetJobPath(
new = self._GetArchivedJobPath(
os.rename(old, new)
logging.debug("Successfully archived job %s",
# Cleaning the cache because we don't know what os.rename actually did
# and to be on the safe side.
class JobQueue:
......@@ -582,7 +617,7 @@ class JobQueue:
def ArchiveJob(self, job_id):
raise NotImplementedError()
def CancelJob(self, job_id):
raise NotImplementedError()
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