mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 22:46:01 -03:30
update to use time function
This commit is contained in:
@@ -7,6 +7,7 @@ from ansible.module_utils.six import PY2
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
from ansible.module_utils.six.moves.http_cookiejar import CookieJar
|
||||
import time
|
||||
import re
|
||||
from json import loads, dumps
|
||||
|
||||
@@ -588,3 +589,26 @@ class TowerAPIModule(TowerModule):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def wait_on_url(self, object_name=None, object_type=None, url=None, timeout=None, interval=None):
|
||||
# Grab our start time to compare against for the timeout
|
||||
start = time.time()
|
||||
result = self.get_endpoint(url)
|
||||
while not result['json']['finished']:
|
||||
# If we are past our time out fail with a message
|
||||
if timeout and timeout < time.time() - start:
|
||||
self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name)
|
||||
self.fail_json(**self.json_output)
|
||||
|
||||
# Put the process to sleep for our interval
|
||||
time.sleep(interval)
|
||||
|
||||
result = self.get_endpoint(url)
|
||||
self.json_output['status'] = result['json']['status']
|
||||
|
||||
# If the job has failed, we want to raise a task failure for that so we get a non-zero response.
|
||||
if result['json']['failed']:
|
||||
self.json_output['msg'] = 'The {0} "{1}" failed'.format(object_type, object_name)
|
||||
self.fail_json(**self.json_output)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user