Created
May 14, 2018 20:17
-
-
Save joelpet/b7ae936ed69d140dff394cdd07b08340 to your computer and use it in GitHub Desktop.
Throttles vdirsyncer in case of an HTTP 429 response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
set -o pipefail | |
cd $(mktemp --directory --suffix '.vdirsyncer') | |
touch vdir_err | |
bash_pid=$$ | |
tail -f vdir_err | grep --line-buffered '429 Client Error' | while read line; do | |
pkill --signal STOP --parent "${bash_pid}" vdirsyncer | |
sleep 300 | |
pkill --signal CONT --parent "${bash_pid}" vdirsyncer | |
done & | |
vdirsyncer sync --max-workers 1 "$@" 2>vdir_err & | |
vdirsyncer_pid=$! | |
trap "kill ${vdirsyncer_pid}" SIGINT | |
wait "${vdirsyncer_pid}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment