Created
February 1, 2012 07:45
-
-
Save aroop/1715817 to your computer and use it in GitHub Desktop.
Dragonfly image processor
This file contains hidden or 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
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 |
This file contains hidden or 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 :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