Skip to content

Instantly share code, notes, and snippets.

@giannafusaro
Created November 6, 2016 18:17
Show Gist options
  • Save giannafusaro/5995f9238f5dac4a2011e79b48e9f0a3 to your computer and use it in GitHub Desktop.
Save giannafusaro/5995f9238f5dac4a2011e79b48e9f0a3 to your computer and use it in GitHub Desktop.
Worker to take a group of records and reprocess all attachments
class PaperclipReprocessWorker
include Sidekiq::Worker
sidekiq_options retry: true
def perform(klass, group)
group.each do |id|
klass.constantize.attachment_definitions.keys.each do |attachment|
begin
klass.constantize.find(id).send(attachment).reprocess!
print "."
rescue Errno::ENOENT
puts "File not found for #{klass} with id #{id}."
puts "#{$!}\n\n"
rescue Paperclip::Error
puts "Paperclip Error for #{klass} with id #{id}."
puts "#{$!}\n\n"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment