Add a global timeout feature

This commit is contained in:
Thomas S Hatch 2011-03-16 10:09:29 -06:00
parent 058e77abbd
commit d102259539
2 changed files with 14 additions and 2 deletions

View file

@ -30,7 +30,13 @@ class SaltCMD(object):
default=5,
type=int,
dest='timeout',
help='Set the return timeout for batch jobs')
help='Set the return timeout for batch jobs; default=5 seconds')
parser.add_option('-g',
'--global-timeout',
default=10,
type=int,
dest='global_timeout',
help='How long to wait if no minions reply; default=10 seconds')
parser.add_option('-E',
'--pcre',
default=False,
@ -59,6 +65,7 @@ class SaltCMD(object):
opts = {}
opts['timeout'] = options.timeout
opts['global_timeout'] = options.global_timeout
opts['pcre'] = options.pcre
opts['list'] = options.list_
if options.query:

View file

@ -102,13 +102,14 @@ class LocalClient(object):
os.chdir(cwd)
return ret
def get_returns(self, jid, minions, timeout=5):
def get_returns(self, jid, minions, timeout=5, global_timeout=10):
'''
This method starts off a watcher looking at the return data for a
specified jid
'''
jid_dir = os.path.join(self.opts['cachedir'], 'jobs', jid)
start = 999999999999
gstart = int(time.time())
ret = {}
# Wait for the hosts to check in
while True:
@ -126,6 +127,10 @@ class LocalClient(object):
return ret
if int(time.time()) > start + timeout:
return ret
if int(time.time()) > gstart + global_timeout and not ret:
# No minions have replied within the specified global timeout,
# return an empty dict
return ret
time.sleep(0.02)
def find_cmd(self, cmd):