Skip to content

Commit 8230291

Browse files
authored
Merge pull request #101 from HSLdevcom/build-at-restart
Option to start build automatically
2 parents 11b8529 + f98abd1 commit 8230291

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

run-builder.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ BUILD_INTERVAL=${BUILD_INTERVAL:-1}
1111
BUILD_INTERVAL_SECONDS=$((($BUILD_INTERVAL - 1)*24*3600))
1212
#start build at this time (GMT):
1313
BUILD_TIME=${BUILD_TIME:-23:00:00}
14+
#option to launch build automatically at early hours
15+
#as a mitigation to crashed builds. zero value disables this feature
16+
AUTO_REBUILD_HOUR=${AUTO_REBUILD_HOUR:-6}
1417
BUILDER_TYPE=${BUILDER_TYPE:-dev}
1518

1619
# param: message text content
@@ -22,9 +25,18 @@ function post_slack_message {
2225
fi
2326
}
2427

28+
# build should be started immediately if service starts before 06:00
29+
# because that is considered as a restart after a service failure
30+
HOUR=$(date +%H)
31+
if [[ "$HOUR" -lt "$AUTO_REBUILD_HOUR" ]]; then
32+
BUILD_AT_LAUNCH=1
33+
else
34+
BUILD_AT_LAUNCH=0
35+
fi
36+
2537
# run data build loop forever, unless build interval is set to zero
2638
while true; do
27-
if [[ "$BUILD_INTERVAL" -gt 0 ]]; then
39+
if [[ "$BUILD_INTERVAL" -gt 0 ]] && [[ "$BUILD_AT_LAUNCH" -eq 0 ]]; then
2840
SLEEP=$(($(date -u -d $BUILD_TIME +%s) - $(date -u +%s) + 1))
2941
if [[ "$SLEEP" -le 0 ]]; then
3042
#today's build time is gone, start counting from tomorrow
@@ -36,6 +48,8 @@ while true; do
3648
sleep $SLEEP
3749
fi
3850

51+
BUILD_AT_LAUNCH=0 #reset
52+
3953
echo "** Launching OTP data builder"
4054

4155
#note: busybox timeout

0 commit comments

Comments
 (0)