Revision 07cd723a lib/jqueue.py

b/lib/jqueue.py
666 666
    finally:
667 667
      self.UpdateJobUnlocked(job)
668 668

  
669
  @utils.LockedMethod
670 669
  @_RequireOpenQueue
671
  def ArchiveJob(self, job_id):
670
  def _ArchiveJobUnlocked(self, job_id):
672 671
    """Archives a job.
673 672

  
674 673
    @type job_id: string
675 674
    @param job_id: Job ID of job to be archived.
676 675

  
677 676
    """
678
    logging.debug("Archiving job %s", job_id)
677
    logging.info("Archiving job %s", job_id)
679 678

  
680 679
    job = self._LoadJobUnlocked(job_id)
681 680
    if not job:
......
695 694

  
696 695
    logging.debug("Successfully archived job %s", job.id)
697 696

  
697
  @utils.LockedMethod
698
  @_RequireOpenQueue
699
  def ArchiveJob(self, job_id):
700
    """Archives a job.
701

  
702
    @type job_id: string
703
    @param job_id: Job ID of job to be archived.
704

  
705
    """
706
    return self._ArchiveJobUnlocked(job_id)
707

  
708
  @utils.LockedMethod
709
  @_RequireOpenQueue
710
  def AutoArchiveJobs(self, age):
711
    """Archives all jobs based on age.
712

  
713
    The method will archive all jobs which are older than the age
714
    parameter. For jobs that don't have an end timestamp, the start
715
    timestamp will be considered. The special '-1' age will cause
716
    archival of all jobs (that are not running or queued).
717

  
718
    @type age: int
719
    @param age: the minimum age in seconds
720

  
721
    """
722
    logging.info("Archiving jobs with age more than %s seconds", age)
723

  
724
    now = time.time()
725
    for jid in self._GetJobIDsUnlocked(archived=False):
726
      job = self._LoadJobUnlocked(jid)
727
      if job.CalcStatus() not in (constants.OP_STATUS_SUCCESS,
728
                                  constants.OP_STATUS_ERROR,
729
                                  constants.OP_STATUS_CANCELED):
730
        continue
731
      if job.end_timestamp is None:
732
        if job.start_timestamp is None:
733
          job_age = job.received_timestamp
734
        else:
735
          job_age = job.start_timestamp
736
      else:
737
        job_age = job.end_timestamp
738

  
739
      if age == -1 or now - job_age[0] > age:
740
        self._ArchiveJobUnlocked(jid)
741

  
698 742
  def _GetJobInfoUnlocked(self, job, fields):
699 743
    row = []
700 744
    for fname in fields:

Also available in: Unified diff