Revision e07f7f7a lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
2435 | 2435 |
|
2436 | 2436 |
return (archived_count, len(all_job_ids) - last_touched) |
2437 | 2437 |
|
2438 |
def QueryJobs(self, job_ids, fields): |
|
2438 |
def _Query(self, fields, qfilter): |
|
2439 |
qobj = query.Query(query.JOB_FIELDS, fields, qfilter=qfilter, |
|
2440 |
namefield="id") |
|
2441 |
|
|
2442 |
job_ids = qobj.RequestedNames() |
|
2443 |
|
|
2444 |
list_all = (job_ids is None) |
|
2445 |
|
|
2446 |
if list_all: |
|
2447 |
# Since files are added to/removed from the queue atomically, there's no |
|
2448 |
# risk of getting the job ids in an inconsistent state. |
|
2449 |
job_ids = self._GetJobIDsUnlocked() |
|
2450 |
|
|
2451 |
jobs = [] |
|
2452 |
|
|
2453 |
for job_id in job_ids: |
|
2454 |
job = self.SafeLoadJobFromDisk(job_id, True, writable=False) |
|
2455 |
if job is not None or not list_all: |
|
2456 |
jobs.append((job_id, job)) |
|
2457 |
|
|
2458 |
return (qobj, jobs, list_all) |
|
2459 |
|
|
2460 |
def QueryJobs(self, fields, qfilter): |
|
2461 |
"""Returns a list of jobs in queue. |
|
2462 |
|
|
2463 |
@type fields: sequence |
|
2464 |
@param fields: List of wanted fields |
|
2465 |
@type qfilter: None or query2 filter (list) |
|
2466 |
@param qfilter: Query filter |
|
2467 |
|
|
2468 |
""" |
|
2469 |
(qobj, ctx, sort_by_name) = self._Query(fields, qfilter) |
|
2470 |
|
|
2471 |
return query.GetQueryResponse(qobj, ctx, sort_by_name=sort_by_name) |
|
2472 |
|
|
2473 |
def OldStyleQueryJobs(self, job_ids, fields): |
|
2439 | 2474 |
"""Returns a list of jobs in queue. |
2440 | 2475 |
|
2441 | 2476 |
@type job_ids: list |
... | ... | |
2447 | 2482 |
the requested fields |
2448 | 2483 |
|
2449 | 2484 |
""" |
2450 |
jobs = [] |
|
2451 |
list_all = False |
|
2452 |
if not job_ids: |
|
2453 |
# Since files are added to/removed from the queue atomically, there's no |
|
2454 |
# risk of getting the job ids in an inconsistent state. |
|
2455 |
job_ids = self._GetJobIDsUnlocked() |
|
2456 |
list_all = True |
|
2485 |
qfilter = qlang.MakeSimpleFilter("id", job_ids) |
|
2457 | 2486 |
|
2458 |
for job_id in job_ids: |
|
2459 |
job = self.SafeLoadJobFromDisk(job_id, True) |
|
2460 |
if job is not None: |
|
2461 |
jobs.append(job.GetInfo(fields)) |
|
2462 |
elif not list_all: |
|
2463 |
jobs.append(None) |
|
2487 |
(qobj, ctx, sort_by_name) = self._Query(fields, qfilter) |
|
2464 | 2488 |
|
2465 |
return jobs
|
|
2489 |
return qobj.OldStyleQuery(ctx, sort_by_name=sort_by_name)
|
|
2466 | 2490 |
|
2467 | 2491 |
@locking.ssynchronized(_LOCK) |
2468 | 2492 |
def PrepareShutdown(self): |
Also available in: Unified diff