Skip to content

Commit

Permalink
fix github actions (less polling)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawnSC committed Apr 27, 2022
1 parent bd2cc8b commit 2b58d27
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

MAXIMUM_SECRET_LENGTH = 20
MAXIMUM_CONTAINER_APP_NAME_LENGTH = 40

SHORT_POLLING_INTERVAL_SECS = 3
LONG_POLLING_INTERVAL_SECS = 10
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_ssh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
5 changes: 3 additions & 2 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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.")
Expand All @@ -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. "
Expand Down

0 comments on commit 2b58d27

Please sign in to comment.