Created
August 22, 2012 15:16
-
-
Save groman-me/3426669 to your computer and use it in GitHub Desktop.
Avoid DB and Queue race
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 User < ActiveRecord::Base | |
after_save :queue_welcome_email, :on => :create | |
private | |
def queue_welcome_email | |
Resque.enqueue(WelcomeEmailJob, Marshal. | |
dump({ :email => self.email, :full_name => "#{self.first_name} #{self.last_name}" })) | |
end | |
end | |
class WelcomeEmailJob | |
@queue = :normal | |
def self.perform(user_data) | |
UserMailer.welcome_email(Marshal.load(user_data)).deliver | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment