From b62d59b3a48a5fae64107d1dc33310da8270f96b Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Fri, 19 Jan 2024 17:09:45 -0800 Subject: [PATCH] [entrypoint] use next run target time to calcualte the sleep time. --- src/entrypoint.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 03861fb..d7276c3 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -136,15 +136,14 @@ main() { fi local STACK="${1:-gantry}" local RETURN_VALUE=0 - local START_TIME PASSED_SECONDS SLEEP_SECONDS + local NEXT_RUN_TARGET_TIME SLEEP_SECONDS while true; do export LOG_SCOPE="${STACK}" - START_TIME=$(date +%s) + NEXT_RUN_TARGET_TIME=$(($(date +%s) + INTERVAL_SECONDS)) gantry "${@}" RETURN_VALUE=$? [ "${INTERVAL_SECONDS}" -le 0 ] && break; - PASSED_SECONDS=$(difference_between "${START_TIME}" "$(date +%s)") - SLEEP_SECONDS=$((INTERVAL_SECONDS - PASSED_SECONDS)) + SLEEP_SECONDS=$((NEXT_RUN_TARGET_TIME - $(date +%s))) if [ "${SLEEP_SECONDS}" -gt 0 ]; then log INFO "Sleeping ${SLEEP_SECONDS} seconds before next update." sleep "${SLEEP_SECONDS}"