Skip to content

Instantly share code, notes, and snippets.

@russ
Created May 2, 2012 17:13
Show Gist options
  • Save russ/2578368 to your computer and use it in GitHub Desktop.
Save russ/2578368 to your computer and use it in GitHub Desktop.
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