Created
November 6, 2016 18:17
-
-
Save giannafusaro/5995f9238f5dac4a2011e79b48e9f0a3 to your computer and use it in GitHub Desktop.
Worker to take a group of records and reprocess all attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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