From fe13c0a83f8511fe09b8c522490fbf7446a9e7de Mon Sep 17 00:00:00 2001 From: Anthony Lin Date: Tue, 7 Nov 2017 17:49:16 +0000 Subject: [PATCH] Update deploy_site script It seems that there is a possibility for Airflow to respond with 'unknown' state for some corner cases. This will cause the deploy_site script to get into infinite loop. The codes in Shipyard has been updated to return 'Unknown (*)' as the state of the action lifecycle in such situations. This P.S. is meant to update the script and to set a default time out of 1.5 hr for the workflow. The time out can be changed by setting a value for $2 (Note that we will need to set query_time, i.e. $1 as well) $ ./deploy_site.sh 120 7200 Change-Id: Ic56ce85f55e9b5fa0c3f537c6158ddc3dc56fab2 --- tools/deploy_site.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/deploy_site.sh b/tools/deploy_site.sh index 0a7c3ade..d5a0b7cf 100755 --- a/tools/deploy_site.sh +++ b/tools/deploy_site.sh @@ -71,13 +71,32 @@ echo # 3) Complete - The action has completed successfully. # 4) Failed - The action has encountered an error, and has failed. # 5) Paused - The action has been paused by a user. +# 6) Unknown (*) - Unknown State for corner cases # # Initialize 'action_lifecycle' to 'Pending' action_lifecycle="Pending" +# Polling for site_deploy action +# Define 'deploy_time_out' and default to 1.5 hrs (5400 seconds) if not provided +# Note that user will need to define query time in this case +deploy_timeout=${2:-5400} +deploy_counter=1 + +check_timeout_counter() { + + # Check total elapsed time + # The default time out is set to 1.5 hrs + # This value can be changed by setting $2 + if [[ $deploy_counter -eq $deploy_timeout ]]; then + echo 'Deploy Site task has timed out.' + break + fi +} + while true; do - if [[ $action_lifecycle == "Complete" ]] || [[ $action_lifecycle == "Failed" ]] || [[ $action_lifecycle == "Paused" ]]; then + if [[ $action_lifecycle == "Complete" ]] || [[ $action_lifecycle == "Failed" ]] || \ + [[ $action_lifecycle == "Paused" ]] || [[ $action_lifecycle == 'Unknown'* ]]; then # Print final results echo -e '\nFinal State of Deployment\n' cat /tmp/get_action_status.json | jq . @@ -100,11 +119,16 @@ do sleep $query_time # Check Dag state - if [[ $action_lifecycle == "Failed" ]] || [[ $action_lifecycle == "Paused" ]]; then + if [[ $action_lifecycle == "Failed" ]] || [[ $action_lifecycle == "Paused" ]] || \ + [[ $action_lifecycle == 'Unknown'* ]]; then echo -e "Dag Execution is in" ${RED}$action_lifecycle${NC} "state\n" else echo -e "Dag Execution is in" ${GREEN}$action_lifecycle${NC} "state\n" fi + + # Step counter and check if deployment has timed out + ((deploy_counter++)) + check_timeout_counter fi done