Skip to content

Instantly share code, notes, and snippets.

@aroop
Created February 1, 2012 07:45
Show Gist options
  • Save aroop/1715817 to your computer and use it in GitHub Desktop.
Save aroop/1715817 to your computer and use it in GitHub Desktop.
Dragonfly image processor
class GenerateImageThumbnailsJob < Struct.new(:photo_id)
def perform
photo = Photo.find(photo_id)
photo.medium_image = photo.image.thumb('940x600')
photo.large_image = photo.image.thumb('450x')
photo.small_image = photo.image.thumb('172x167#c')
photo.save
end
def success(job)
puts ">>> Successful finished job: #{job.id}"
end
def failure(job)
puts ">>> Job #{job.id} failed to resize image"
end
end
namespace :data do
task :photos => :environment do
Photo.select("id").where(:medium_image_uid => nil).find_in_batches do |photos|
photos.each do |photo|
Delayed::Job.enqueue GenerateImageThumbnailsJob.new(photo.id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment