diff --git a/src/containerapp/azext_containerapp/_constants.py b/src/containerapp/azext_containerapp/_constants.py index 212b7ca4adc..d6852056fce 100644 --- a/src/containerapp/azext_containerapp/_constants.py +++ b/src/containerapp/azext_containerapp/_constants.py @@ -5,3 +5,6 @@ MAXIMUM_SECRET_LENGTH = 20 MAXIMUM_CONTAINER_APP_NAME_LENGTH = 40 + +SHORT_POLLING_INTERVAL_SECS = 3 +LONG_POLLING_INTERVAL_SECS = 10 diff --git a/src/containerapp/azext_containerapp/_ssh_utils.py b/src/containerapp/azext_containerapp/_ssh_utils.py index a5a77a601c0..057216a321f 100644 --- a/src/containerapp/azext_containerapp/_ssh_utils.py +++ b/src/containerapp/azext_containerapp/_ssh_utils.py @@ -162,7 +162,7 @@ def ping_container_app(app): if site: resp = requests.get(f'https://{site}') if not resp.ok: - logger.info("Got bad status pinging app: {resp.status_code}") + logger.info(f"Got bad status pinging app: {resp.status_code}") else: logger.info("Could not fetch site external URL") diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 00cb5b1e7ef..ce3c22e5e13 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -715,8 +715,9 @@ def _create_github_action( # need to trigger the workflow manually if it already exists (performing an update) try: - GitHubActionClient.show(cmd=app.cmd, resource_group_name=app.resource_group.name, name=app.name) - trigger_workflow(token, repo, app.name, branch) + action = GitHubActionClient.show(cmd=app.cmd, resource_group_name=app.resource_group.name, name=app.name) + if action: + trigger_workflow(token, repo, app.name, branch) except: # pylint: disable=bare-except pass diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index ddbea0a92f8..964a9953d7f 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -19,7 +19,7 @@ from ._clients import ContainerAppClient from ._client_factory import handle_raw_exception, providers_client_factory, cf_resource_groups, log_analytics_client_factory, log_analytics_shared_key_client_factory -from ._constants import MAXIMUM_CONTAINER_APP_NAME_LENGTH +from ._constants import MAXIMUM_CONTAINER_APP_NAME_LENGTH, SHORT_POLLING_INTERVAL_SECS, LONG_POLLING_INTERVAL_SECS logger = get_logger(__name__) @@ -31,7 +31,7 @@ def validate_container_app_name(name): # original implementation at azure.cli.command_modules.role.custom.create_service_principal_for_rbac -# reimplemented to remove unnecessary warning statements +# reimplemented to remove incorrect warning statements def create_service_principal_for_rbac( # pylint:disable=too-many-statements,too-many-locals, too-many-branches, unused-argument, inconsistent-return-statements cmd, name=None, years=None, create_cert=False, cert=None, scopes=None, role=None, show_auth_for_sdk=None, skip_assignment=False, keyvault=None): @@ -192,7 +192,7 @@ def await_github_action(cmd, token, repo, branch, name, resource_group_name, tim gh_action_status = "InProgress" while gh_action_status == "InProgress": - time.sleep(1) + time.sleep(SHORT_POLLING_INTERVAL_SECS) animation.tick() gh_action_status = safe_get(show_github_action(cmd, name, resource_group_name), "properties", "operationState") if (datetime.utcnow() - start).seconds >= timeout_secs: @@ -203,19 +203,17 @@ def await_github_action(cmd, token, repo, branch, name, resource_group_name, tim workflow = None while workflow is None: - workflow = get_workflow(github_repo, name) animation.tick() - time.sleep(1) + time.sleep(SHORT_POLLING_INTERVAL_SECS) + workflow = get_workflow(github_repo, name) animation.flush() if (datetime.utcnow() - start).seconds >= timeout_secs: raise CLIInternalError("Timed out while waiting for the Github action to start.") - animation.flush() - animation.tick() - animation.flush() runs = workflow.get_runs() while runs is None or not [r for r in runs if r.status in ('queued', 'in_progress')]: + time.sleep(SHORT_POLLING_INTERVAL_SECS) runs = workflow.get_runs() if (datetime.utcnow() - start).seconds >= timeout_secs: raise CLIInternalError("Timed out while waiting for the Github action to be started.") @@ -227,13 +225,14 @@ def await_github_action(cmd, token, repo, branch, name, resource_group_name, tim run_id = run.id status = run.status while status in ('queued', 'in_progress'): - time.sleep(3) + time.sleep(LONG_POLLING_INTERVAL_SECS) animation.tick() status = github_repo.get_workflow_run(run_id).status animation.flush() if (datetime.utcnow() - start).seconds >= timeout_secs: raise CLIInternalError("Timed out while waiting for the Github action to complete.") + animation.flush() # needed to clear the animation from the terminal run = github_repo.get_workflow_run(run_id) if run.status != "completed" or run.conclusion != "success": raise ValidationError("Github action build or deployment failed. "