Created
November 6, 2016 18:16
-
-
Save giannafusaro/cfc06195101aeaf7353da6e9560c935c to your computer and use it in GitHub Desktop.
Rake task to reprocesses all attachments for given class
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
namespace :paperclip do | |
desc "Reprocesses all attachments for given class" | |
# rake paperclip:reprocess[User,800,'where','some_sort_of_scope_or_filter IS true'] | |
task :reprocess, [:class, :batch_size, :where, :clause] => :environment do |t, args| | |
klass = args[:class].constantize | |
batch_size = args[:batch_size]&.to_i || 100 | |
records = klass.all | |
records = klass.send(args[:where], args[:clause]) if args[:where] && args[:clause] | |
records.find_in_batches(batch_size: batch_size) do |group| | |
PaperclipReprocessWorker.perform_async(klass, group.map(&:id)) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment