Skip to content

Commit

Permalink
Merge pull request #5482 from pulibrary/5079-large-mosiac-list
Browse files Browse the repository at this point in the history
Use temp file to pass raster paths to cogeo-mosaic
  • Loading branch information
tpendragon authored Oct 24, 2022
2 parents 30855de + 7c23e55 commit 6d63b2f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ruby 2.7.5
nodejs 16.15.0
java zulu-8.56.0.23
java zulu-8.58.0.13
python 3.9.1
yarn 1.22.10
13 changes: 10 additions & 3 deletions app/services/mosaic_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ def initialize(output_path:, raster_paths:)
end

def run
_stdout_str, error_str, status = Open3.capture3(mosaic_command)
raise StandardError, error_str unless status.success?
mosaic_command do |command|
_stdout_str, error_str, status = Open3.capture3(command)
raise StandardError, error_str unless status.success?
end

true
end

private

# need the key to read the images
def mosaic_command
"echo \"#{raster_paths}\" | #{access_key} #{secret_access_key} LC_ALL=C.UTF-8 LANG=C.UTF-8 cogeo-mosaic create - -o #{output_path}"
temp_file = Tempfile.new
temp_file.write(raster_paths.join("\n"))
temp_file.rewind
yield "#{access_key} #{secret_access_key} LC_ALL=C.UTF-8 LANG=C.UTF-8 cogeo-mosaic create #{temp_file.path} -o #{output_path}"
temp_file.close
end

def access_key
Expand Down
2 changes: 1 addition & 1 deletion app/services/tile_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def mosaic_path
document_path = Valkyrie::Storage::Disk::BucketedStorage.new(base_path: base_path).generate(resource: resource, original_filename: fingerprinted_filename, file: nil).to_s
return document_path if storage_adapter.find_by(id: mosaic_file_id)
rescue Valkyrie::StorageAdapter::FileNotFound
raise Error unless MosaicGenerator.new(output_path: tmp_file.path, raster_paths: raster_paths.join("\n")).run
raise Error unless MosaicGenerator.new(output_path: tmp_file.path, raster_paths: raster_paths).run

# build default mosaic file
build_node(default_filename)
Expand Down
2 changes: 1 addition & 1 deletion spec/services/tile_metadata_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
generator = described_class.new(resource: map_set)

generator.path
expect(MosaicGenerator).to have_received(:new).with(output_path: anything, raster_paths: file_set.file_metadata.first.cloud_uri)
expect(MosaicGenerator).to have_received(:new).with(output_path: anything, raster_paths: [file_set.file_metadata.first.cloud_uri])
end
end

Expand Down

0 comments on commit 6d63b2f

Please sign in to comment.