Created
May 2, 2012 17:13
-
-
Save russ/2578368 to your computer and use it in GitHub Desktop.
This file contains 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 Video < ActiveRecord::Base | |
after_save :background_process_attachment | |
def background_process_attachment | |
video = self.class.find(id) | |
return if video.nil? | |
to_process = [] | |
to_fetch = [] | |
%w(attachment trailer watermarked wmv).each do |name| | |
to_fetch << name if video.send(:"#{name}_source_url_changed?") && !video.send(:"#{name}_source_url").blank? | |
to_process << name if video.send(:"#{name}_changed?") | |
end | |
if video.state == 'error' && !(to_fetch.empty? && to_process.empty?) | |
video.update_column(:state, 'waiting') | |
video.update_column(:error_message, nil) | |
end | |
if not to_process.empty? | |
Resque.enqueue(ProcessMultipleAttachmentsJob, self.class.name, video.id, to_process) | |
elsif not to_fetch.empty? | |
Resque.enqueue(FetchMultipleAttachmentsJob, self.class.name, video.id, to_fetch) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment