Skip to content

Instantly share code, notes, and snippets.

@giannafusaro
Created November 6, 2016 18:16
Show Gist options
  • Save giannafusaro/cfc06195101aeaf7353da6e9560c935c to your computer and use it in GitHub Desktop.
Save giannafusaro/cfc06195101aeaf7353da6e9560c935c to your computer and use it in GitHub Desktop.
Rake task to reprocesses all attachments for given class
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