Routing: start once the offline build's extracts are in, not after Planetiler; merged file keeps the .osm.pbf extension osmium needs
This commit is contained in:
1 parent
ac7c7f3ba9
commit
58ca871662
4 files changed
+35
-15
No files matched your search
@@ -33,13 +33,13 @@ module Maptool
|
||||
|
||||
# Routing covers the offline map's selected countries. While an offline
|
||||
# build is running (it may be downloading those very extracts), the
|
||||
# request waits for it — PmtilesBuilder calls offline_build_finished.
|
||||
# request waits for its downloads — PmtilesBuilder calls extracts_ready.
|
||||
def self.request_build(data_dir)
|
||||
codes = PmtilesBuilder.selected_regions(data_dir)
|
||||
raise PmtilesBuilder::BuildError, "select at least one region first" if codes.empty?
|
||||
|
||||
MUTEX.synchronize do
|
||||
if PmtilesBuilder.offline_status[:state] == "running"
|
||||
if PmtilesBuilder.fetching_extracts?
|
||||
@pending = true
|
||||
return
|
||||
end
|
||||
@@ -67,17 +67,18 @@ module Maptool
|
||||
# one merged file. Its image has no osmium; this container does.
|
||||
def self.merge_and_request(data_dir, codes)
|
||||
merged = File.join(dir(data_dir), "merged.osm.pbf")
|
||||
part = File.join(dir(data_dir), "merged.part.osm.pbf") # osmium picks the format by extension
|
||||
inputs = codes.map { |code| extract_path(data_dir, code) }
|
||||
stdout, stderr, status = Open3.capture3(PmtilesBuilder.osmium_bin, "merge", "-O", *inputs, "-o", "#{merged}.part")
|
||||
stdout, stderr, status = Open3.capture3(PmtilesBuilder.osmium_bin, "merge", "-O", *inputs, "-o", part)
|
||||
raise PmtilesBuilder::BuildError, "osmium merge failed: #{(stderr + stdout)[-2000..] || stderr + stdout}" unless status.success?
|
||||
|
||||
File.rename("#{merged}.part", merged)
|
||||
File.rename(part, merged)
|
||||
MUTEX.synchronize do
|
||||
write_request(data_dir, codes, "routing/merged.osm.pbf")
|
||||
@merging = nil
|
||||
end
|
||||
rescue StandardError => e
|
||||
FileUtils.rm_f("#{merged}.part")
|
||||
FileUtils.rm_f(part)
|
||||
MUTEX.synchronize { @merging = { state: "error", message: e.message, finished_at: Time.now.utc.iso8601 } }
|
||||
end
|
||||
private_class_method :merge_and_request
|
||||
@@ -88,7 +89,7 @@ module Maptool
|
||||
end
|
||||
private_class_method :write_request
|
||||
|
||||
def self.offline_build_finished(data_dir)
|
||||
def self.extracts_ready(data_dir)
|
||||
pending = MUTEX.synchronize { @pending.tap { @pending = false } }
|
||||
request_build(data_dir) if pending
|
||||
rescue PmtilesBuilder::BuildError
|
||||
@@ -99,7 +100,7 @@ module Maptool
|
||||
# started_at, message.
|
||||
def self.build_status(data_dir)
|
||||
pending, merging = MUTEX.synchronize { [@pending, @merging] }
|
||||
return { state: "running", step: "waiting for the offline map build" } if pending
|
||||
return { state: "running", step: "waiting for the offline map downloads" } if pending
|
||||
return merging if merging
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user