mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 21:37:42 -02:30
Add --interval to launch monitor command (#14068)
Co-authored-by: Jessica Steurer <70719005+jay-steurer@users.noreply.github.com>
This commit is contained in:
@@ -56,6 +56,11 @@ class Launchable(object):
|
|||||||
parser.choices[self.action].add_argument('--monitor', action='store_true', help='If set, prints stdout of the launched job until it finishes.')
|
parser.choices[self.action].add_argument('--monitor', action='store_true', help='If set, prints stdout of the launched job until it finishes.')
|
||||||
parser.choices[self.action].add_argument('--action-timeout', type=int, help='If set with --monitor or --wait, time out waiting on job completion.')
|
parser.choices[self.action].add_argument('--action-timeout', type=int, help='If set with --monitor or --wait, time out waiting on job completion.')
|
||||||
parser.choices[self.action].add_argument('--wait', action='store_true', help='If set, waits until the launched job finishes.')
|
parser.choices[self.action].add_argument('--wait', action='store_true', help='If set, waits until the launched job finishes.')
|
||||||
|
parser.choices[self.action].add_argument(
|
||||||
|
'--interval',
|
||||||
|
type=float,
|
||||||
|
help='If set with --monitor or --wait, amount of time to wait in seconds between api calls. Minimum value is 2.5 seconds to avoid overwhelming the api',
|
||||||
|
)
|
||||||
|
|
||||||
launch_time_options = self.page.connection.options(self.options_endpoint)
|
launch_time_options = self.page.connection.options(self.options_endpoint)
|
||||||
if launch_time_options.ok:
|
if launch_time_options.ok:
|
||||||
@@ -71,6 +76,7 @@ class Launchable(object):
|
|||||||
self.page.connection.session,
|
self.page.connection.session,
|
||||||
print_stdout=not kwargs.get('wait'),
|
print_stdout=not kwargs.get('wait'),
|
||||||
action_timeout=kwargs.get('action_timeout'),
|
action_timeout=kwargs.get('action_timeout'),
|
||||||
|
interval=kwargs.get('interval'),
|
||||||
)
|
)
|
||||||
if status:
|
if status:
|
||||||
response.json['status'] = status
|
response.json['status'] = status
|
||||||
@@ -83,6 +89,7 @@ class Launchable(object):
|
|||||||
'monitor': kwargs.pop('monitor', False),
|
'monitor': kwargs.pop('monitor', False),
|
||||||
'wait': kwargs.pop('wait', False),
|
'wait': kwargs.pop('wait', False),
|
||||||
'action_timeout': kwargs.pop('action_timeout', False),
|
'action_timeout': kwargs.pop('action_timeout', False),
|
||||||
|
'interval': kwargs.pop('interval', 5),
|
||||||
}
|
}
|
||||||
response = self.page.get().related.get(self.action).post(kwargs)
|
response = self.page.get().related.get(self.action).post(kwargs)
|
||||||
self.monitor(response, **monitor_kwargs)
|
self.monitor(response, **monitor_kwargs)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from .utils import cprint, color_enabled, STATUS_COLORS
|
|||||||
from awxkit.utils import to_str
|
from awxkit.utils import to_str
|
||||||
|
|
||||||
|
|
||||||
def monitor_workflow(response, session, print_stdout=True, action_timeout=None, interval=0.25):
|
def monitor_workflow(response, session, print_stdout=True, action_timeout=None, interval=5):
|
||||||
get = response.url.get
|
get = response.url.get
|
||||||
payload = {
|
payload = {
|
||||||
'order_by': 'finished',
|
'order_by': 'finished',
|
||||||
@@ -58,7 +58,7 @@ def monitor_workflow(response, session, print_stdout=True, action_timeout=None,
|
|||||||
# all at the end
|
# all at the end
|
||||||
fetch(seen)
|
fetch(seen)
|
||||||
|
|
||||||
time.sleep(0.25)
|
time.sleep(max(2.5, interval))
|
||||||
json = get().json
|
json = get().json
|
||||||
if json.finished:
|
if json.finished:
|
||||||
fetch(seen)
|
fetch(seen)
|
||||||
@@ -68,7 +68,7 @@ def monitor_workflow(response, session, print_stdout=True, action_timeout=None,
|
|||||||
return get().json.status
|
return get().json.status
|
||||||
|
|
||||||
|
|
||||||
def monitor(response, session, print_stdout=True, action_timeout=None, interval=0.25):
|
def monitor(response, session, print_stdout=True, action_timeout=None, interval=5):
|
||||||
get = response.url.get
|
get = response.url.get
|
||||||
payload = {'order_by': 'start_line', 'no_truncate': True}
|
payload = {'order_by': 'start_line', 'no_truncate': True}
|
||||||
if response.type == 'job':
|
if response.type == 'job':
|
||||||
@@ -105,7 +105,7 @@ def monitor(response, session, print_stdout=True, action_timeout=None, interval=
|
|||||||
if next_line:
|
if next_line:
|
||||||
payload['start_line__gte'] = next_line
|
payload['start_line__gte'] = next_line
|
||||||
|
|
||||||
time.sleep(0.25)
|
time.sleep(max(2.5, interval))
|
||||||
json = get().json
|
json = get().json
|
||||||
if json.event_processing_finished is True or json.status in ('error', 'canceled'):
|
if json.event_processing_finished is True or json.status in ('error', 'canceled'):
|
||||||
fetch(next_line)
|
fetch(next_line)
|
||||||
|
|||||||
Reference in New Issue
Block a user