class ActiveStorage::Service::MirrorService
-
headers_for_direct_upload
*url_for_direct_upload
*url
*exists?
*download
have the files uploaded to them. Aprimary
service is designated to answer calls to:
Wraps a set of mirror services and provides a single ActiveStorage::Service object that will all
def self.build(primary:, mirrors:, name:, configurator:, **options) # :nodoc:
Stitch together from named services.
def self.build(primary:, mirrors:, name:, configurator:, **options) # :nodoc: new( primary: configurator.build(primary), mirrors: mirrors.collect { |mirror_name| configurator.build mirror_name } ).tap do |service_instance| service_instance.name = name end end
def delete(key)
def delete(key) perform_across_services :delete, key end
def delete_prefixed(prefix)
def delete_prefixed(prefix) perform_across_services :delete_prefixed, prefix end
def each_service(&block)
def each_service(&block) [ primary, *mirrors ].each(&block) end
def initialize(primary:, mirrors:)
def initialize(primary:, mirrors:) @primary, @mirrors = primary, mirrors end
def mirror(key, checksum:)
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
def perform_across_services(method, *args)
def perform_across_services(method, *args) # FIXME: Convert to be threaded each_service.collect do |service| service.public_send method, *args end end
def upload(key, io, checksum: nil, **options)
Upload the +io+ to the +key+ specified to all services. If a +checksum+ is provided, all services will
def upload(key, io, checksum: nil, **options) each_service.collect do |service| io.rewind service.upload key, io, checksum: checksum, **options end end