Created
April 17, 2012 23:09
-
-
Save JonCrawford/2409768 to your computer and use it in GitHub Desktop.
Use after_commit instead of after_create for Resque jobs.
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
# Redis is faster than Mysql so it may cause a RecordNotFound to happen if enqueued from after_create | |
before_create :set_recently_opened | |
after_commit :if => :recently_opened? do |record| | |
Resque.enqueue StoreAfterCreate, record.id | |
UserMailer.store_signup(record.owner_user_id, record.id).deliver | |
end | |
def set_recently_opened | |
@recently_opened = true | |
end | |
def recently_opened? | |
@recently_opened | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment