Revision 911a495b lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
223 | 223 |
|
224 | 224 |
|
225 | 225 |
class JobStorage(object): |
226 |
_RE_JOB_FILE = re.compile(r"^job-\d+$")
|
|
226 |
_RE_JOB_FILE = re.compile(r"^job-(\d+)$")
|
|
227 | 227 |
|
228 | 228 |
def __init__(self): |
229 | 229 |
self._lock = threading.Lock() |
... | ... | |
313 | 313 |
def _GetJobPath(self, job_id): |
314 | 314 |
return os.path.join(constants.QUEUE_DIR, "job-%s" % job_id) |
315 | 315 |
|
316 |
def _GetJobIDsUnlocked(self, archived=False): |
|
317 |
"""Return all known job IDs. |
|
318 |
|
|
319 |
If the parameter archived is True, archived jobs IDs will be |
|
320 |
included. Currently this argument is unused. |
|
321 |
|
|
322 |
""" |
|
323 |
jfiles = self._ListJobFiles() |
|
324 |
return [m.group(1) for m in |
|
325 |
[self._RE_JOB_FILE.match(name) for name in jfiles]] |
|
326 |
|
|
316 | 327 |
def _ListJobFiles(self): |
317 | 328 |
assert self.lock_fd, "Queue should be open" |
318 | 329 |
|
319 | 330 |
return [name for name in utils.ListVisibleFiles(constants.QUEUE_DIR) |
320 | 331 |
if self._RE_JOB_FILE.match(name)] |
321 | 332 |
|
322 |
def _LoadJobUnlocked(self, filepath):
|
|
333 |
def _LoadJobUnlocked(self, job_id):
|
|
323 | 334 |
assert self.lock_fd, "Queue should be open" |
324 | 335 |
|
336 |
filepath = self._GetJobPath(job_id) |
|
325 | 337 |
logging.debug("Loading job from %s", filepath) |
326 | 338 |
try: |
327 | 339 |
fd = open(filepath, "r") |
... | ... | |
337 | 349 |
return _QueuedJob.Restore(self, data) |
338 | 350 |
|
339 | 351 |
def _GetJobsUnlocked(self, job_ids): |
340 |
if job_ids: |
|
341 |
files = [self._GetJobPath(job_id) for job_id in job_ids] |
|
342 |
else: |
|
343 |
files = [os.path.join(constants.QUEUE_DIR, filename) |
|
344 |
for filename in self._ListJobFiles()] |
|
352 |
if not job_ids: |
|
353 |
job_ids = self._GetJobIDsUnlocked() |
|
345 | 354 |
|
346 |
return [self._LoadJobUnlocked(filepath) for filepath in files]
|
|
355 |
return [self._LoadJobUnlocked(job_id) for job_id in job_ids]
|
|
347 | 356 |
|
348 | 357 |
@utils.LockedMethod |
349 | 358 |
def GetJobs(self, job_ids): |
Also available in: Unified diff