fix(deploy): the sidecars' downloads try again within the hour after a failed round
A failed BRouter segment or listing, a failed tile cut or an unwritable folder waited the whole refresh period, 30 days without routes or a map; they try again after an hour, doubling to a day. Photon's failed download backs off from a day to a week, and a dead Photon is noticed within a minute. The downloads' network is an ordinary bridge the three share, as the comments now say. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
0240a80faf
commit
ba77248930
1 changed files with 102 additions and 19 deletions
|
|
@ -3,7 +3,9 @@
|
|||
# newest of Protomaps' daily builds of the planet, cut to MAP_REGION (`west,south,
|
||||
# east,north` in degrees; by default Europe's, the box BRouter's segments cover) at
|
||||
# zooms 0 to 15, into /tiles/europe.pmtiles; again every MAP_REFRESH_DAYS days (30)
|
||||
# where a newer build has come. The cut is written into /tiles/next/ and moved over
|
||||
# where a newer build has come; after a round where the builds' list or the cut
|
||||
# failed, again in an hour, the wait doubling up to a day while rounds keep failing.
|
||||
# The cut is written into /tiles/next/ and moved over
|
||||
# the old one, so the server never reads half a file; until it is done, the old one
|
||||
# serves. Both at once take twice a cut's room.
|
||||
set -eu
|
||||
|
|
@ -12,9 +14,13 @@ builds=https://build-metadata.protomaps.dev/builds.json
|
|||
region=${MAP_REGION:--25,35,45,75}
|
||||
days=${MAP_REFRESH_DAYS:-30}
|
||||
cd /tiles
|
||||
mkdir -p next
|
||||
|
||||
refresh() {
|
||||
complete=0
|
||||
if ! mkdir -p next; then
|
||||
echo "/tiles/next can't be made; the tiles stay as they are." >&2
|
||||
return 0
|
||||
fi
|
||||
build=$(curl -fsS "$builds" | grep -o '"key": *"[0-9]\{8\}\.pmtiles"' |
|
||||
grep -o '[0-9]\{8\}\.pmtiles' | sort | tail -n 1) || build=
|
||||
if [ -z "$build" ]; then
|
||||
|
|
@ -23,6 +29,7 @@ refresh() {
|
|||
fi
|
||||
if [ -e europe.build ] && [ "$(cat europe.build)" = "$build" ]; then
|
||||
echo "The tiles are $build's, the newest."
|
||||
complete=1
|
||||
return 0
|
||||
fi
|
||||
rm -f next/europe.pmtiles
|
||||
|
|
@ -31,13 +38,33 @@ refresh() {
|
|||
mv next/europe.pmtiles europe.pmtiles
|
||||
echo "$build" >europe.build
|
||||
echo "The tiles are $build's now, $(du -h europe.pmtiles | cut -f1)."
|
||||
complete=1
|
||||
else
|
||||
rm -f next/europe.pmtiles
|
||||
echo "The cut of $build failed; the tiles stay as they are." >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Seconds to wait after the $1th incomplete round in a row: $2, doubling up to $3.
|
||||
backoff() {
|
||||
pause=$2 n=1
|
||||
while [ "$n" -lt "$1" ] && [ "$pause" -lt "$3" ]; do
|
||||
pause=$((pause * 2)) n=$((n + 1))
|
||||
done
|
||||
if [ "$pause" -gt "$3" ]; then pause=$3; fi
|
||||
echo "$pause"
|
||||
}
|
||||
|
||||
failures=0
|
||||
while :; do
|
||||
refresh
|
||||
sleep $((days * 86400))
|
||||
if [ "$complete" -eq 1 ]; then
|
||||
failures=0
|
||||
sleep $((days * 86400))
|
||||
else
|
||||
failures=$((failures + 1))
|
||||
pause=$(backoff "$failures" 3600 86400)
|
||||
echo "The round wasn't complete; trying again in $((pause / 60)) minutes." >&2
|
||||
sleep "$pause"
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue