4 ms·
This is a nice feature at the minute-resolution level. I think something at the second-resolution level would be helpful too. For example, I have a cronjob on m
by compumike 3y ago
This is a nice feature at the minute-resolution level. I think something at the second-resolution level would be helpful too. For example, I have a cronjob on my Raspberry Pi at home that runs every minute and does a simple check-in with Heii On-Call so I get alerted if there's a FIOS outage or the pi breaks. I ended up writing a little bash script like this:
#!/bin/bash
set -e
HEIIONCALL_API_KEY="redacted_api_key_goes_here"
HEIIONCALL_TRIGGER_ID="redacted_trigger_id_goes_here"
AUTHORIZATION_HEADER="Authorization: Bearer ${HEIIONCALL_API_KEY}"
CHECKIN_URL="https://api.heiioncall.com./triggers/${HEIIONCALL_TRIGGER_ID}/checkin"
if [ "$1" != "--now" ]; then
RANDOM_SLEEP=$[ ( $RANDOM % 55 ) + 1 ]
echo "Sleeping ${RANDOM_SLEEP} seconds before checkin..."
sleep ${RANDOM_SLEEP}s
fi
echo "Checking in..."
exec curl \
-X POST \
--retry 5 --retry-connrefused --retry-max-time 15 --retry-delay 1 \
-H "${AUTHORIZATION_HEADER}" \
"${CHECKIN_URL}"
This script ~/bin/heiioncall-checkin.sh gets called by crond every minute at exactly :00 seconds, so my expected maximum timeout between check-ins is approximately 120 seconds. And I can skip the sleep with "--now" flag for testing. But I'd much rather have this random offset behavior be something optionally built-in to cron, I suppose.
- ciupicri 3y agoWhy aren't you using systemd timer unit with RandomizedDelaySec? [1] [1]: https://www.freedesktop.org/software/systemd/man/systemd.timer.html#RandomizedDelaySec= https://www.freedesktop.org/software/systemd/man/systemd.tim...