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