Skip to content

Instantly share code, notes, and snippets.

@groman-me
Created August 22, 2012 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groman-me/3426669 to your computer and use it in GitHub Desktop.
Save groman-me/3426669 to your computer and use it in GitHub Desktop.
Avoid DB and Queue race
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