class BackupStorage::Service::MirrorService

Wraps a set of mirror services and provides a single `BackupStorage::Service` object that will all have the files uploaded to them. A `primary` service is designated to answer calls to `download`, `exists?`, and `url`.

Attributes

mirrors[R]
primary[R]

Public Class Methods

new(primary:, mirrors:) click to toggle source
# File lib/backup_storage/service/mirror_service.rb, line 18
def initialize(primary:, mirrors:)
  @primary, @mirrors = primary, mirrors
end

Public Instance Methods

delete(key) click to toggle source

Delete the file at the `key` on all services.

# File lib/backup_storage/service/mirror_service.rb, line 31
def delete(key)
  perform_across_services :delete, key
end
upload(key, io, checksum: nil) click to toggle source

Upload the `io` to the `key` specified to all services. If a `checksum` is provided, all services will ensure a match when the upload has completed or raise an `BackupStorage::IntegrityError`.

# File lib/backup_storage/service/mirror_service.rb, line 24
def upload(key, io, checksum: nil)
  each_service.collect do |service|
    service.upload key, io.tap(&:rewind), checksum: checksum
  end
end

Private Instance Methods

each_service(&block) click to toggle source
# File lib/backup_storage/service/mirror_service.rb, line 36
def each_service(&block)
  [ primary, *mirrors ].each(&block)
end
perform_across_services(method, *args) click to toggle source
# File lib/backup_storage/service/mirror_service.rb, line 40
def perform_across_services(method, *args)
  # FIXME: Convert to be threaded
  each_service.collect do |service|
    service.public_send method, *args
  end
end