Skip to content

Commit

Permalink
Handle current minute correctly and add test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
deitch committed Feb 12, 2019
1 parent d41b9c5 commit bb2aec8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function wait_for_cron() {
# we keep a copy of the actual compare time, because we might shift the compare time in a moment
local comparesec=$compare
# there must be at least 60 seconds between last run and next run, so if it is less than 60 seconds,
# add 60 seconds to $compare
# add differential seconds to $compare
local compareDiff=$(($compare - $last_run))
if [ $compareDiff -lt 60 ]; then
compare=$(($compare + $(( 60-$compareDiff )) ))
Expand All @@ -229,9 +229,9 @@ function wait_for_cron() {
# cron only works in minutes, so we want to round down to the current minute
# e.g. if we are at 20:06:25, we need to treat it as 20:06:00, or else our waittime will be -25
# on the other hand, if we are at 20:06:00, do not round it down
local current_seconds=$(date --date="@$compare" +"%-S")
local current_seconds=$(date --date="@$comparesec" +"%-S")
if [ $current_seconds -ne 0 ]; then
compare=$(( $compare - $current_seconds ))
comparesec=$(( $comparesec - $current_seconds ))
fi

# reminder, cron format is:
Expand Down
3 changes: 3 additions & 0 deletions test/test_cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ cronline=(
"1 * * * *"
"1 * * * *"
"* 1 * * *"
"1 * * * *"
#"10 2 10 * *"
)
nowtime=(
"2018.10.10-10:01:00"
"2018.10.10-10:00:00"
"2018.10.10-10:00:00"
"2018.10.10-10:01:10" # this line tests that we use the current minute, and not wait for "-10"
)
waittime=(
"0"
"60"
"54000"
"0"
)

for ((i=0; i< ${#cronline[@]}; i++)); do
Expand Down

0 comments on commit bb2aec8

Please sign in to comment.