From f7dd5848f817bb42cb06eadc5444ec390aa813ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Thu, 22 Feb 2018 11:53:19 +0100 Subject: Migrating single tasks file to a galaxy role --- files/clever-wait-deploy.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 files/clever-wait-deploy.sh (limited to 'files/clever-wait-deploy.sh') diff --git a/files/clever-wait-deploy.sh b/files/clever-wait-deploy.sh new file mode 100644 index 0000000..99088cc --- /dev/null +++ b/files/clever-wait-deploy.sh @@ -0,0 +1,50 @@ +#!/bin/bash -e + +function deploying { + checkStatus "$1" "IN PROGRESS" +} + +function deployed { + checkStatus "$1" "OK" +} + +function inactive { + local commit="$1" + [[ "$(clever activity | grep "$commit" | grep "DEPLOY" | wc -l)" == "0" ]] +} + +function checkStatus { + local commit="$1" + local status="$2" + [[ "$(clever activity | grep "$commit" | grep "${status}\s\+DEPLOY" | wc -l)" == "1" ]] +} + +function check { + local timeout=600 # 10 minutes + local commit="$1" + local samplingTime=5 + + echo "Waiting for deployment start..." + while inactive "$commit" -a $timeout -gt 0 + do + sleep $samplingTime + let "timeout-=$samplingTime" + done + + # Wait for completion + echo "Deployement in progress..." + while deploying "$commit" -a $timeout -gt 0 + do + sleep $samplingTime + let "timeout-=$samplingTime" + done + + if [ $samplingTime -eq 0 ] + then + echo "Timeout" + fi + + deployed "$commit" +} + +check "$(git rev-parse HEAD)" -- cgit v1.2.3