tf-a-lts-docs-watcher.sh: wait_for_build: Add timeout

In the testing, in some cases build status could not be acquired, because
the tag/slug was actually built before (then tags are being reused for
testing).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I6ebc52970f5e061b6c8347807f6eeccfbcabf1a8
diff --git a/scripts/tf-a-lts-docs-watcher.sh b/scripts/tf-a-lts-docs-watcher.sh
index 7b6f1ca..40a3bf1 100755
--- a/scripts/tf-a-lts-docs-watcher.sh
+++ b/scripts/tf-a-lts-docs-watcher.sh
@@ -74,6 +74,7 @@
 
 function wait_for_build() {
     version=$1
+    retry=0
     while true; do
         status=$(curl -s -H "Authorization: Token ${RTD_API_TOKEN}" "${RTD_API}/builds/" | \
                    jq -r ".results | map(select(.version==\"$version\")) | .[0].state.code")
@@ -81,7 +82,14 @@
         if [ "$status" == "finished" ]; then
             break
         fi
-        sleep 10
+
+        retry=$((retry + 1))
+        if [ $retry -gt 40 ]; then
+            echo "Could not confirm that ReadTheDoc slug ${version} was built in the alloted time."
+            break
+        fi
+
+        sleep 15
     done
 }