instance method mirror

Ruby on Rails edge

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

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

key req
checksum keyreq
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

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close