Revision c609f802
b/lib/jqueue.py | ||
---|---|---|
292 | 292 |
|
293 | 293 |
return "%s%010d" % (prefix, job_id) |
294 | 294 |
|
295 |
def _ShouldJobBeArchivedUnlocked(self, job): |
|
296 |
if job.GetStatus() not in (constants.JOB_STATUS_CANCELED, |
|
297 |
constants.JOB_STATUS_SUCCESS, |
|
298 |
constants.JOB_STATUS_ERROR): |
|
299 |
logging.debug("Job %s is not yet done", job.id) |
|
300 |
return False |
|
301 |
return True |
|
302 |
|
|
295 | 303 |
|
296 | 304 |
class DiskJobStorage(JobStorageBase): |
297 | 305 |
_RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE) |
... | ... | |
538 | 546 |
def UpdateJob(self, job): |
539 | 547 |
return self._UpdateJobUnlocked(job) |
540 | 548 |
|
549 |
@utils.LockedMethod |
|
541 | 550 |
def ArchiveJob(self, job_id): |
542 |
raise NotImplementedError() |
|
551 |
"""Archives a job. |
|
552 |
|
|
553 |
@type job_id: string |
|
554 |
@param job_id: Job ID of job to be archived. |
|
555 |
|
|
556 |
""" |
|
557 |
logging.debug("Archiving job %s", job_id) |
|
558 |
|
|
559 |
job = self._LoadJobUnlocked(job_id) |
|
560 |
if not job: |
|
561 |
logging.debug("Job %s not found", job_id) |
|
562 |
return |
|
563 |
|
|
564 |
if not self._ShouldJobBeArchivedUnlocked(job): |
|
565 |
return |
|
566 |
|
|
567 |
try: |
|
568 |
old = self._GetJobPath(job.id) |
|
569 |
new = self._GetArchivedJobPath(job.id) |
|
570 |
|
|
571 |
os.rename(old, new) |
|
572 |
|
|
573 |
logging.debug("Successfully archived job %s", job.id) |
|
574 |
finally: |
|
575 |
# Cleaning the cache because we don't know what os.rename actually did |
|
576 |
# and to be on the safe side. |
|
577 |
self._CleanCacheUnlocked([]) |
|
543 | 578 |
|
544 | 579 |
|
545 | 580 |
class JobQueue: |
... | ... | |
582 | 617 |
return job.id |
583 | 618 |
|
584 | 619 |
def ArchiveJob(self, job_id): |
585 |
raise NotImplementedError()
|
|
620 |
self._jobs.ArchiveJob(job_id)
|
|
586 | 621 |
|
587 | 622 |
def CancelJob(self, job_id): |
588 | 623 |
raise NotImplementedError() |
Also available in: Unified diff