instance method
mirror
Ruby on Rails edge
Since v6.1.7.10Signature
mirror(key, checksum:)
Copy the file at the key from the primary service to each of the mirrors where it doesn’t already exist. Both the existence checks and the uploads run in parallel across mirrors using the internal thread pool.
Parameters
-
keyreq -
checksumkeyreq
Source
# File activestorage/lib/active_storage/service/mirror_service.rb, line 67
def mirror(key, checksum:)
instrument :mirror, key: key, checksum: checksum do
mirrors_in_need_of_mirroring = mirrors_needing_mirroring(key)
if mirrors_in_need_of_mirroring.any?
metadata = ActiveStorage::Blob.find_by(key: key)&.service_metadata || {}
primary.open(key, checksum: checksum, verify: checksum.present?) do |io|
io.rewind
content = io.read.freeze
tasks = mirrors_in_need_of_mirroring.map do |service|
Concurrent::Promise.execute(executor: @executor) do
service.upload key, StringIO.new(content), checksum: checksum, **metadata
end
end
tasks.each(&:value!)
end
end
end
end
Defined in activestorage/lib/active_storage/service/mirror_service.rb line 67
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Service::MirrorService