Method: ActiveStorage::Service::MirrorService#mirror

Defined in:
activestorage/lib/active_storage/service/mirror_service.rb

#mirror(key, checksum:) ⇒ Object

Copy the file at the key from the primary service to each of the mirrors where it doesn’t already exist.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'activestorage/lib/active_storage/service/mirror_service.rb', line 66

def mirror(key, checksum:)
  instrument :mirror, key: key, checksum: checksum do
    if (mirrors_in_need_of_mirroring = mirrors.select { |service| !service.exist?(key) }).any?
      primary.open(key, checksum: checksum) do |io|
        mirrors_in_need_of_mirroring.each do |service|
          io.rewind
          service.upload key, io, checksum: checksum
        end
      end
    end
  end
end