Revision ce594241

b/lib/jqueue.py
264 264
    self.context = context
265 265

  
266 266

  
267
class DiskJobStorage(object):
267
class JobStorageBase(object):
268
  def __init__(self, id_prefix):
269
    self.id_prefix = id_prefix
270

  
271
    if id_prefix:
272
      prefix_pattern = re.escape("%s-" % id_prefix)
273
    else:
274
      prefix_pattern = ""
275

  
276
    # Apart from the prefix, all job IDs are numeric
277
    self._re_job_id = re.compile(r"^%s\d+$" % prefix_pattern)
278

  
279
  def OwnsJobId(self, job_id):
280
    return self._re_job_id.match(job_id)
281

  
282
  def FormatJobID(self, job_id):
283
    if not isinstance(job_id, (int, long)):
284
      raise errors.ProgrammerError("Job ID '%s' not numeric" % job_id)
285
    if job_id < 0:
286
      raise errors.ProgrammerError("Job ID %s is negative" % job_id)
287

  
288
    if self.id_prefix:
289
      prefix = "%s-" % self.id_prefix
290
    else:
291
      prefix = ""
292

  
293
    return "%s%010d" % (prefix, job_id)
294

  
295

  
296
class DiskJobStorage(JobStorageBase):
268 297
  _RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
269 298

  
270
  def __init__(self):
299
  def __init__(self, id_prefix):
300
    JobStorageBase.__init__(self, id_prefix)
301

  
271 302
    self._lock = threading.Lock()
272 303
    self._memcache = {}
273 304
    self._my_hostname = utils.HostInfo().name
......
383 414
      if not result[node]:
384 415
        logging.error("copy of job queue file to node %s failed", node)
385 416

  
386
    return str(serial)
417
    return self.FormatJobID(serial)
387 418

  
388 419
  def _GetJobPath(self, job_id):
389 420
    return os.path.join(constants.QUEUE_DIR, "job-%s" % job_id)
......
400 431

  
401 432
    """
402 433
    jfiles = self._ListJobFiles()
403
    jlist = [int(m.group(1)) for m in
434
    jlist = [m.group(1) for m in
404 435
             [self._RE_JOB_FILE.match(name) for name in jfiles]]
405 436
    jlist.sort()
406 437
    return jlist
......
510 541
class JobQueue:
511 542
  """The job queue.
512 543

  
513
   """
544
  """
514 545
  def __init__(self, context):
515 546
    self._lock = threading.Lock()
516
    self._jobs = DiskJobStorage()
547
    self._jobs = DiskJobStorage("")
517 548
    self._wpool = _JobQueueWorkerPool(context)
518 549

  
519 550
    for job in self._jobs.GetJobs(None):

Also available in: Unified diff