class BigShift::Cleaner

Public Class Methods

new(s3_resource, cs_service, options={}) click to toggle source
# File lib/bigshift/cleaner.rb, line 3
def initialize(s3_resource, cs_service, options={})
  @s3_resource = s3_resource
  @cs_service = cs_service
  @logger = options[:logger] || NullLogger.new
end

Public Instance Methods

cleanup(unload_manifest, cs_bucket_name) click to toggle source
# File lib/bigshift/cleaner.rb, line 9
def cleanup(unload_manifest, cs_bucket_name)
  cleanup_s3(unload_manifest)
  cleanup_cs(cs_bucket_name, unload_manifest)
  nil
end

Private Instance Methods

cleanup_cs(bucket_name, unload_manifest) click to toggle source
# File lib/bigshift/cleaner.rb, line 24
def cleanup_cs(bucket_name, unload_manifest)
  @logger.info(sprintf('Deleting %d files from gs://%s/%s', unload_manifest.count, bucket_name, unload_manifest.prefix))
  unload_manifest.keys.each do |key|
    @cs_service.delete_object(bucket_name, key)
  end
end
cleanup_s3(unload_manifest) click to toggle source
# File lib/bigshift/cleaner.rb, line 17
def cleanup_s3(unload_manifest)
  objects = unload_manifest.keys.map { |k| {key: k} }
  objects << {key: unload_manifest.manifest_key}
  @logger.info(sprintf('Deleting %d files from s3://%s/%s (including the manifest file)', objects.size, unload_manifest.bucket_name, unload_manifest.prefix))
  @s3_resource.bucket(unload_manifest.bucket_name).delete_objects(delete: {objects: objects})
end