Map data pull over brick's nginx: X-Accel-Buffering: no on map files (buffered, nginx's 1 GB temp file cap ended every bigger download there); each attempt resumes from the part on disk (curl's --retry kept its first offset); a file that can't be written is skipped, not the whole run
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-29 17:52:02 +01:00
1 parent 62045be0f7
commit 5c023619ec
2 files changed
+21 -9

No files matched your search

+17 -9
View File
@@ -45,20 +45,28 @@ while IFS=$'\t' read -r size mtime path; do
local_file="$DATA/$path"
[ -f "$local_file" ] && [ "$(stat -c '%s %Y' "$local_file")" = "$size $mtime" ] && continue
mkdir -p "$(dirname "$local_file")"
part="$local_file.part"
# One file that can't be written (a directory the container owns) is
# that file's failure, not the whole run's.
if ! mkdir -p "$(dirname "$local_file")" || ! touch "$part.version" 2>/dev/null; then
echo "pull-maps: can't write $local_file, skipping" >&2
failed=$((failed + 1))
continue
fi
# A partial download of another version of the file starts over.
[ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] || rm -f "$part"
[ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] && [ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -le "$size" ] || rm -f "$part"
echo "$size $mtime" > "$part.version"
echo "pull-maps: $path ($((size / 1048576)) MB)"
# Into a temp file, renamed when complete: the app and Valhalla keep
# reading the old copy until restarted.
if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" != "$size" ]; then
# --speed-*: a connection that went dead (Wi-Fi switched, proxy gone)
# is dropped after a minute without data and the retry resumes.
curl -fsS --retry 10 --retry-all-errors --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \
--get --data-urlencode "path=$path" "$server/api/sync/maps/file" || true
fi
# reading the old copy until restarted. Each attempt resumes from what's
# there (curl's own --retry keeps its first offset); --speed-*: a
# connection that went dead (Wi-Fi switched) is dropped after a minute.
stalls=0
while have=$(stat -c %s "$part" 2>/dev/null || echo 0); [ "$have" -lt "$size" ] && [ "$stalls" -lt 5 ]; do
curl -fsS --retry 3 --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \
--get --data-urlencode "path=$path" "$server/api/sync/maps/file" || sleep 5
[ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -gt "$have" ] && stalls=0 || stalls=$((stalls + 1))
done
if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" = "$size" ]; then
touch -d "@$mtime" "$part"
mv "$part" "$local_file"