Slow down polling for jobs after we've been idle a while
authorSteve McIntyre <steve@einval.com>
Tue, 6 Nov 2018 16:28:43 +0000 (16:28 +0000)
committerSteve McIntyre <steve@einval.com>
Tue, 6 Nov 2018 16:28:43 +0000 (16:28 +0000)
bin/build-client

index 28539b6..6d563d6 100755 (executable)
@@ -85,7 +85,16 @@ grab_and_build () {
     return 0
 }    
 
+NO_JOBS_SLOW_SLEEP=20
+SLEEP_NO_JOB_DEFAULT=10
+SLEEP_NO_JOB_SLOW=600
+SLEEP_TIME=$SLEEP_NO_JOB_DEFAULT
+
 while true; do
+    # How many times in a row have we asked for a job and not got
+    # anything? If this gets high, back off
+    NO_JOBS_COUNT=0
+
     if [ -f /chroot/rebuildd/EXIT ]; then
        echo "Found EXIT file, stopping here"
        exit 0
@@ -98,11 +107,21 @@ while true; do
     BNUM_PKG_VER_ARCH=$(ssh build@jack ./bin/get_package $HOSTNAME)
     BNUM=$(echo $BNUM_PKG_VER_ARCH | cut -d " " -f1)
     PKG_VER_ARCH=$(echo $BNUM_PKG_VER_ARCH | cut -d " " -f2)
+
+    # If we didn't get a job, sleep for a while
     if [ "$PKG_VER_ARCH" = "NOPACKAGE" ]; then
        DATE=$(date)
-       echo "$DATE: Nothing to do, wait..."
-       sleep 10
+       NO_JOBS_COUNT=$(($NO_JOBS_COUNT + 1))
+       echo "$DATE: Nothing to do ($NO_JOBS_COUNT times), wait..."
+       if [ $NO_JOBS_COUNT -eq $NO_JOBS_SLOW_SLEEP ]; then
+           echo "$DATE: No work for $NO_JOBS_SLOW_SLEEP, slowing down"
+           SLEEP_TIME=$SLEEP_NO_JOB_SLOW # Back off
+       fi
+       sleep $SLEEP_TIME
        continue
+    else
+       NO_JOBS_COUNT=0
+       SLEEP_TIME=$SLEEP_NO_JOB_DEFAULT
     fi
     
     PKG=$(echo $PKG_VER_ARCH | cut -d _ -f1)