Fixed up async and polling logic.

This commit is contained in:
Michael DeHaan 2012-03-11 19:27:43 -04:00
parent 5be1a612d3
commit 49a636d8a0
4 changed files with 89 additions and 24 deletions

View file

@ -32,6 +32,7 @@ import ansible.connection
import Queue
import random
import jinja2
import time
from ansible.utils import *
################################################
@ -376,12 +377,16 @@ class Runner(object):
self.module_args = [ "jid=%s" % jid ]
clock = self.background
while (clock >= 0):
time.sleep(self.poll_interval)
clock -= self.poll_interval
result = self._execute_normal_module(conn, host, tmp)
(host, ok, real_result) = result
self.async_poll_callback(self, clock, self.poll_interval, ok, host, jid, real_result)
if 'finished' in real_result or 'failed' in real_result:
clock=-1
elif (clock < 0 and not 'finished' in real_result):
return [ host, False, "timer expired" ]
self._delete_remote_files(conn, tmp)
conn.close()
return result

View file

@ -177,9 +177,9 @@ def path_dwim(basedir, given):
def async_poll_status(runner, clock, poll_interval, ok, host, jid, result):
if ok and 'finished' in result:
print "<job %s> finished on %s, %s" % (jid, host, result)
print "<job %s> finished on %s" % (jid, host)
elif not ok or 'failed' in result:
print "<job %s> FAILED on %s, %s" % (jid, host, result)
print "<job %s> FAILED on %s" % (jid, host)
else:
print "<job %s> polling on %s, %s remaining" % (jid, host, clock)