Revision 6c5a7090 lib/cli.py
b/lib/cli.py | ||
---|---|---|
405 | 405 |
if cl is None: |
406 | 406 |
cl = GetClient() |
407 | 407 |
|
408 |
state = None |
|
409 |
lastmsg = None |
|
408 |
prev_job_info = None |
|
409 |
prev_logmsg_serial = None |
|
410 |
|
|
410 | 411 |
while True: |
411 |
state = cl.WaitForJobChange(job_id, ["status", "ticker"], state) |
|
412 |
if not state: |
|
412 |
result = cl.WaitForJobChange(job_id, ["status"], prev_job_info, |
|
413 |
prev_logmsg_serial) |
|
414 |
if not result: |
|
413 | 415 |
# job not found, go away! |
414 | 416 |
raise errors.JobLost("Job with id %s lost" % job_id) |
415 | 417 |
|
418 |
# Split result, a tuple of (field values, log entries) |
|
419 |
(job_info, log_entries) = result |
|
420 |
(status, ) = job_info |
|
421 |
|
|
422 |
if log_entries: |
|
423 |
for log_entry in log_entries: |
|
424 |
(serial, timestamp, _, message) = log_entry |
|
425 |
if callable(feedback_fn): |
|
426 |
feedback_fn(log_entry[1:]) |
|
427 |
else: |
|
428 |
print "%s %s" % (time.ctime(utils.MergeTime(timestamp)), message) |
|
429 |
prev_logmsg_serial = max(prev_logmsg_serial, serial) |
|
430 |
|
|
416 | 431 |
# TODO: Handle canceled and archived jobs |
417 |
status = state[0] |
|
418 |
if status in (constants.JOB_STATUS_SUCCESS, constants.JOB_STATUS_ERROR): |
|
432 |
elif status in (constants.JOB_STATUS_SUCCESS, constants.JOB_STATUS_ERROR): |
|
419 | 433 |
break |
420 |
msg = state[1] |
|
421 |
if msg is not None and msg != lastmsg: |
|
422 |
if callable(feedback_fn): |
|
423 |
feedback_fn(msg) |
|
424 |
else: |
|
425 |
print "%s %s" % (time.ctime(utils.MergeTime(msg[0])), msg[2]) |
|
426 |
lastmsg = msg |
|
434 |
|
|
435 |
prev_job_info = job_info |
|
427 | 436 |
|
428 | 437 |
jobs = cl.QueryJobs([job_id], ["status", "opresult"]) |
429 | 438 |
if not jobs: |
Also available in: Unified diff