I have a rake task to convert my photos from attachment_fu to Carrierwave.
Is there a way to run the task :convert
multiple times in parallel to make this faster ?
Here is my working task :
namespace :photos do
task :convert => :environment do
Item.all.each do |item|
item.photos.each do |photo|
new_photo = ItemPhoto.new :photo => File.open(File.join(Rails.root, "public", photo.public_filename)),
:item_id => item.id
new_photo.save
end
item.update_attribute :migrated, true
end
end
end
Take a look at the parallel gem
It could look like this for 8 concurrent processes:
namespace :photos do
task :convert => :environment do
Parallel.each(Item.all, :in_processes => 8) do |item|
item.photos.each do |photo|
new_photo = ItemPhoto.new :photo => File.open(File.join(Rails.root, "public", photo.public_filename)),
:item_id => item.id
new_photo.save
end
item.update_attribute :migrated, true
end
end
end
`