Commit 804fce06 by Feanil Patel

Catch keyerrors.

parent 256493c5
...@@ -407,60 +407,63 @@ def poll_sqs_ansible(): ...@@ -407,60 +407,63 @@ def poll_sqs_ansible():
now = int(time.time()) now = int(time.time())
if buf: if buf:
if (now - max([msg['recv_ts'] for msg in buf])) > args.msg_delay: try:
# sort by TS instead of recv_ts if (now - max([msg['recv_ts'] for msg in buf])) > args.msg_delay:
# because the sqs timestamp is not as # sort by TS instead of recv_ts
# accurate # because the sqs timestamp is not as
buf.sort(key=lambda k: k['msg']['TS']) # accurate
to_disp = buf.pop(0) buf.sort(key=lambda k: k['msg']['TS'])
if 'START' in to_disp['msg']: to_disp = buf.pop(0)
print '\n{:0>2.0f}:{:0>5.2f} {} : Starting "{}"'.format( if 'START' in to_disp['msg']:
to_disp['msg']['TS'] / 60, print '\n{:0>2.0f}:{:0>5.2f} {} : Starting "{}"'.format(
to_disp['msg']['TS'] % 60, to_disp['msg']['TS'] / 60,
to_disp['msg']['PREFIX'], to_disp['msg']['TS'] % 60,
to_disp['msg']['START']), to_disp['msg']['PREFIX'],
to_disp['msg']['START']),
elif 'TASK' in to_disp['msg']:
print "\n{:0>2.0f}:{:0>5.2f} {} : {}".format( elif 'TASK' in to_disp['msg']:
to_disp['msg']['TS'] / 60, print "\n{:0>2.0f}:{:0>5.2f} {} : {}".format(
to_disp['msg']['TS'] % 60, to_disp['msg']['TS'] / 60,
to_disp['msg']['PREFIX'], to_disp['msg']['TS'] % 60,
to_disp['msg']['TASK']), to_disp['msg']['PREFIX'],
last_task = to_disp['msg']['TASK'] to_disp['msg']['TASK']),
elif 'OK' in to_disp['msg']: last_task = to_disp['msg']['TASK']
if args.verbose: elif 'OK' in to_disp['msg']:
print "\n" if args.verbose:
for key, value in to_disp['msg']['OK'].iteritems(): print "\n"
print " {:<15}{}".format(key, value) for key, value in to_disp['msg']['OK'].iteritems():
else: print " {:<15}{}".format(key, value)
if to_disp['msg']['OK']['changed']:
changed = "*OK*"
else: else:
changed = "OK" if to_disp['msg']['OK']['changed']:
print " {}".format(changed), changed = "*OK*"
task_report.append({ else:
'TASK': last_task, changed = "OK"
'INVOCATION': to_disp['msg']['OK']['invocation'], print " {}".format(changed),
'DELTA': to_disp['msg']['delta'], task_report.append({
}) 'TASK': last_task,
elif 'FAILURE' in to_disp['msg']: 'INVOCATION': to_disp['msg']['OK']['invocation'],
print " !!!! FAILURE !!!!", 'DELTA': to_disp['msg']['delta'],
for key, value in to_disp['msg']['FAILURE'].iteritems(): })
print " {:<15}{}".format(key, value) elif 'FAILURE' in to_disp['msg']:
raise Exception("Failed Ansible run") print " !!!! FAILURE !!!!",
elif 'STATS' in to_disp['msg']: for key, value in to_disp['msg']['FAILURE'].iteritems():
print "\n{:0>2.0f}:{:0>5.2f} {} : COMPLETE".format( print " {:<15}{}".format(key, value)
to_disp['msg']['TS'] / 60, raise Exception("Failed Ansible run")
to_disp['msg']['TS'] % 60, elif 'STATS' in to_disp['msg']:
to_disp['msg']['PREFIX']) print "\n{:0>2.0f}:{:0>5.2f} {} : COMPLETE".format(
to_disp['msg']['TS'] / 60,
# Since 3 ansible plays get run. to_disp['msg']['TS'] % 60,
# We see the COMPLETE message 3 times to_disp['msg']['PREFIX'])
# wait till the last one to end listening
# for new messages. # Since 3 ansible plays get run.
completed += 1 # We see the COMPLETE message 3 times
if completed >= NUM_PLAYBOOKS: # wait till the last one to end listening
return (to_disp['msg']['TS'], task_report) # for new messages.
completed += 1
if completed >= NUM_PLAYBOOKS:
return (to_disp['msg']['TS'], task_report)
except KeyError:
print "Failed to print status from message: {}".format(to_disp)
if not messages: if not messages:
# wait 1 second between sqs polls # wait 1 second between sqs polls
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment