Routing build status: show the container's step while a request is queued; Apply during a build of the same regions queues nothing
This commit is contained in:
1 parent
59447c56f2
commit
92efe118b0
2 files changed
+23
-1
No files matched your search
@@ -44,6 +44,10 @@ module Maptool
|
|||||||
missing = codes.reject { |code| File.exist?(extract_path(data_dir, code)) }
|
missing = codes.reject { |code| File.exist?(extract_path(data_dir, code)) }
|
||||||
raise PmtilesBuilder::BuildError, "no downloaded map data for #{missing.join(", ")}, build the offline map first" if missing.any?
|
raise PmtilesBuilder::BuildError, "no downloaded map data for #{missing.join(", ")}, build the offline map first" if missing.any?
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
write_json(File.join(dir(data_dir), "build-request.json"), regions: codes, requested_at: Time.now.utc.iso8601)
|
write_json(File.join(dir(data_dir), "build-request.json"), regions: codes, requested_at: Time.now.utc.iso8601)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -59,9 +63,11 @@ module Maptool
|
|||||||
# started_at, message.
|
# started_at, message.
|
||||||
def self.build_status(data_dir)
|
def self.build_status(data_dir)
|
||||||
return { state: "running", step: "waiting for the offline map build" } if MUTEX.synchronize { @pending }
|
return { state: "running", step: "waiting for the offline map build" } if MUTEX.synchronize { @pending }
|
||||||
|
status = read_json(File.join(dir(data_dir), "status.json"))
|
||||||
|
return status if status&.dig(:state) == "running" # the container is building; a queued request runs next
|
||||||
return { state: "running", step: "waiting for the routing container" } if File.exist?(File.join(dir(data_dir), "build-request.json"))
|
return { state: "running", step: "waiting for the routing container" } if File.exist?(File.join(dir(data_dir), "build-request.json"))
|
||||||
|
|
||||||
read_json(File.join(dir(data_dir), "status.json")) || { state: "idle" }
|
status || { state: "idle" }
|
||||||
end
|
end
|
||||||
|
|
||||||
# The DataFileRow status shape, plus whether Valhalla answers.
|
# The DataFileRow status shape, plus whether Valhalla answers.
|
||||||
|
|||||||
@@ -60,6 +60,22 @@ class RoutingTest < Minitest::Test
|
|||||||
assert_equal "packing tiles", Maptool::Routing.build_status(@data)[:step]
|
assert_equal "packing tiles", Maptool::Routing.build_status(@data)[:step]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_apply_during_a_build_of_the_same_regions_queues_nothing
|
||||||
|
File.write(File.join(@data, "geofabrik_cache", "SK.osm.pbf"), "pbf")
|
||||||
|
FileUtils.mkdir_p(File.join(@routing, "staging"))
|
||||||
|
File.write(File.join(@routing, "staging", "request.json"), JSON.generate(regions: %w[SK]))
|
||||||
|
File.write(File.join(@routing, "status.json"), JSON.generate(state: "running", step: "routing graph (SK)"))
|
||||||
|
Maptool::Routing.request_build(@data)
|
||||||
|
refute File.exist?(File.join(@routing, "build-request.json"))
|
||||||
|
|
||||||
|
# Different countries do queue, and the running build's step still shows.
|
||||||
|
File.write(File.join(@data, "geofabrik_cache", "CZ.osm.pbf"), "pbf")
|
||||||
|
Maptool::PmtilesBuilder.set_selected_regions(@data, %w[SK CZ])
|
||||||
|
Maptool::Routing.request_build(@data)
|
||||||
|
assert File.exist?(File.join(@routing, "build-request.json"))
|
||||||
|
assert_equal "routing graph (SK)", Maptool::Routing.build_status(@data)[:step]
|
||||||
|
end
|
||||||
|
|
||||||
def test_the_vehicle_is_validated_and_stored
|
def test_the_vehicle_is_validated_and_stored
|
||||||
assert_equal Maptool::Routing::DEFAULT_VEHICLE, Maptool::Routing.vehicle(@data)
|
assert_equal Maptool::Routing::DEFAULT_VEHICLE, Maptool::Routing.vehicle(@data)
|
||||||
Maptool::Routing.save_vehicle(@data, "height" => "3.4", "width" => "2.4", "length" => "8", "weight" => "4.2")
|
Maptool::Routing.save_vehicle(@data, "height" => "3.4", "width" => "2.4", "length" => "8", "weight" => "4.2")
|
||||||
|
|||||||
Reference in new issue
Block a user