Skip to content

Instantly share code, notes, and snippets.

@joelpet
Created May 14, 2018 20:17
Show Gist options
  • Save joelpet/b7ae936ed69d140dff394cdd07b08340 to your computer and use it in GitHub Desktop.
Save joelpet/b7ae936ed69d140dff394cdd07b08340 to your computer and use it in GitHub Desktop.
Throttles vdirsyncer in case of an HTTP 429 response
#!/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