Revision 9f7b4967 lib/jqueue.py

b/lib/jqueue.py
1031 1031

  
1032 1032
    return job
1033 1033

  
1034
  def _GetJobsUnlocked(self, job_ids):
1035
    """Return a list of jobs based on their IDs.
1036

  
1037
    @type job_ids: list
1038
    @param job_ids: either an empty list (meaning all jobs),
1039
        or a list of job IDs
1040
    @rtype: list
1041
    @return: the list of job objects
1042

  
1043
    """
1044
    if not job_ids:
1045
      job_ids = self._GetJobIDsUnlocked()
1046

  
1047
    return [self._LoadJobUnlocked(job_id) for job_id in job_ids]
1048

  
1049 1034
  def SafeLoadJobFromDisk(self, job_id):
1050 1035
    """Load the given job file from disk.
1051 1036

  
......
1426 1411

  
1427 1412
    return (archived_count, len(all_job_ids) - last_touched)
1428 1413

  
1429
  @utils.LockedMethod
1430
  @_RequireOpenQueue
1431 1414
  def QueryJobs(self, job_ids, fields):
1432 1415
    """Returns a list of jobs in queue.
1433 1416

  
1434
    This is a wrapper of L{_GetJobsUnlocked}, which actually does the
1435
    processing for each job.
1436

  
1437 1417
    @type job_ids: list
1438 1418
    @param job_ids: sequence of job identifiers or None for all
1439 1419
    @type fields: list
......
1444 1424

  
1445 1425
    """
1446 1426
    jobs = []
1427
    list_all = False
1428
    if not job_ids:
1429
      # Since files are added to/removed from the queue atomically, there's no
1430
      # risk of getting the job ids in an inconsistent state.
1431
      job_ids = self._GetJobIDsUnlocked()
1432
      list_all = True
1447 1433

  
1448
    for job in self._GetJobsUnlocked(job_ids):
1449
      if job is None:
1450
        jobs.append(None)
1451
      else:
1434
    for job_id in job_ids:
1435
      job = self.SafeLoadJobFromDisk(job_id)
1436
      if job is not None:
1452 1437
        jobs.append(job.GetInfo(fields))
1438
      elif not list_all:
1439
        jobs.append(None)
1453 1440

  
1454 1441
    return jobs
1455 1442

  

Also available in: Unified diff