diff --git a/bin/routing-service.sh b/bin/routing-service.sh index 0381a69..92abc43 100755 --- a/bin/routing-service.sh +++ b/bin/routing-service.sh @@ -62,6 +62,10 @@ build() { mv "$R/build-request.json" "$S/request.json" regions=$(python3 -c 'import json,sys; print(" ".join(json.load(open(sys.argv[1]))["regions"]))' "$S/request.json") pbf=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("pbf", ""))' "$S/request.json") + if [ -z "$pbf" ] && [ "$(echo $regions | wc -w)" -gt 1 ]; then # a request from before the merge + status error "" "this request has several countries but no merged extract; click Apply again" + return 1 + fi if [ -n "$pbf" ]; then # several countries, merged by maptool (Valhalla breaks on overlapping extracts) ln "/data/$pbf" "$R/pbf/" || { status error "" "missing $pbf"; return 1; } else @@ -103,7 +107,8 @@ if [ -f "$S/request.json" ] && [ ! -f "$R/build-request.json" ]; then fi serve while true; do - [ -f "$R/build-request.json" ] && build + # A failed build isn't retried by the next restart. + [ -f "$R/build-request.json" ] && { build || rm -f "$S/request.json"; } # valhalla_service died (or never started): start it again. if [ -n "$SERVICE_PID" ] && ! kill -0 "$SERVICE_PID" 2>/dev/null; then serve; fi sleep 10 & wait $! # interruptible, so the trap above runs right away diff --git a/lib/maptool/routing.rb b/lib/maptool/routing.rb index 98f1600..390476b 100644 --- a/lib/maptool/routing.rb +++ b/lib/maptool/routing.rb @@ -48,7 +48,7 @@ module Maptool # Apply again while the same countries are building: nothing to queue. running = read_json(File.join(dir(data_dir), "staging", "request.json")) - return if running && running[:regions] == codes && read_json(File.join(dir(data_dir), "status.json"))&.dig(:state) == "running" + return if running && running[:regions] == codes && running.key?(:pbf) == (codes.size > 1) && read_json(File.join(dir(data_dir), "status.json"))&.dig(:state) == "running" return if @merging&.dig(:state) == "running"