Revision 85a1c57d

b/lib/jqueue.py
901 901
    return utils.PathJoin(constants.JOB_QUEUE_ARCHIVE_DIR,
902 902
                          cls._GetArchiveDirectory(job_id), "job-%s" % job_id)
903 903

  
904
  @classmethod
905
  def _ExtractJobID(cls, name):
906
    """Extract the job id from a filename.
907

  
908
    @type name: str
909
    @param name: the job filename
910
    @rtype: job id or None
911
    @return: the job id corresponding to the given filename,
912
        or None if the filename does not represent a valid
913
        job file
914

  
915
    """
916
    m = cls._RE_JOB_FILE.match(name)
917
    if m:
918
      return m.group(1)
919
    else:
920
      return None
921

  
922
  def _GetJobIDsUnlocked(self):
904
  def _GetJobIDsUnlocked(self, sort=True):
923 905
    """Return all known job IDs.
924 906

  
925 907
    The method only looks at disk because it's a requirement that all
926 908
    jobs are present on disk (so in the _memcache we don't have any
927 909
    extra IDs).
928 910

  
911
    @type sort: boolean
912
    @param sort: perform sorting on the returned job ids
929 913
    @rtype: list
930 914
    @return: the list of job IDs
931 915

  
932 916
    """
933
    jlist = [self._ExtractJobID(name) for name in self._ListJobFiles()]
934
    jlist = utils.NiceSort(jlist)
917
    jlist = []
918
    for filename in utils.ListVisibleFiles(constants.QUEUE_DIR, sort=False):
919
      m = self._RE_JOB_FILE.match(filename)
920
      if m:
921
        jlist.append(m.group(1))
922
    if sort:
923
      jlist = utils.NiceSort(jlist)
935 924
    return jlist
936 925

  
937
  def _ListJobFiles(self):
938
    """Returns the list of current job files.
939

  
940
    @rtype: list
941
    @return: the list of job file names
942

  
943
    """
944
    return [name for name in utils.ListVisibleFiles(constants.QUEUE_DIR)
945
            if self._RE_JOB_FILE.match(name)]
946

  
947 926
  def _LoadJobUnlocked(self, job_id):
948 927
    """Loads a job from the disk or memory.
949 928

  
......
1051 1030
      raise errors.JobQueueDrainError("Job queue is drained, refusing job")
1052 1031

  
1053 1032
    # Check job queue size
1054
    size = len(self._ListJobFiles())
1033
    size = len(self._GetJobIDsUnlocked(sort=False))
1055 1034
    if size >= constants.JOB_QUEUE_SIZE_SOFT_LIMIT:
1056 1035
      # TODO: Autoarchive jobs. Make sure it's not done on every job
1057 1036
      # submission, though.

Also available in: Unified diff