Skip to content

Commit 81af39e

Browse files
committed
Make AnsibleTower checkout/execute actions more resilient
We've been seeing some issues with service interruptions in AAP under high load. While the jobs do complete successfully, awxkit bails when encountering the connection issue. With this change, we simple enter a retry loop when monitoring job status.
1 parent ddda515 commit 81af39e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

broker/providers/ansible_tower.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import click
99
from dynaconf import Validator
1010
from logzero import logger
11+
from requests.exceptions import ConnectionError
1112

1213
from broker import exceptions
1314
from broker.helpers import eval_filter, find_origin, yaml
@@ -41,6 +42,19 @@ def convert_pseudonamespaces(attr_dict):
4142
return out_dict
4243

4344

45+
def resilient_job_wait(job, timeout=None):
46+
"""Wait for a job to complete. Retry on errors."""
47+
timeout = timeout or settings.ANSIBLETOWER.workflow_timeout
48+
completed = False
49+
while not completed:
50+
try:
51+
job.wait_until_completed(timeout=timeout)
52+
completed = True
53+
except ConnectionError as err:
54+
logger.error(f"Error occurred while waiting for job: {err}")
55+
logger.info("Retrying job wait...")
56+
57+
4458
class JobExecutionError(exceptions.ProviderError):
4559
"""Raised when a job execution fails."""
4660

@@ -605,7 +619,7 @@ def execute(self, **kwargs): # noqa: PLR0912,PLR0915 - Possible TODO refactor
605619
job_ui_url = url_parser.urljoin(self.url, f"/#/{subject}s/{job_number}")
606620
helpers.emit(api_url=job_api_url, ui_url=job_ui_url)
607621
logger.info(f"Waiting for job: \nAPI: {job_api_url}\nUI: {job_ui_url}")
608-
job.wait_until_completed(timeout=settings.ANSIBLETOWER.workflow_timeout)
622+
resilient_job_wait(job)
609623
if job.status != "successful":
610624
message_data = {
611625
f"{subject.capitalize()} Status": job.status,

0 commit comments

Comments
 (0)