Skip to content

Instantly share code, notes, and snippets.

@JonCrawford
Created April 17, 2012 23:09
Show Gist options
  • Save JonCrawford/2409768 to your computer and use it in GitHub Desktop.
Save JonCrawford/2409768 to your computer and use it in GitHub Desktop.
Use after_commit instead of after_create for Resque jobs.
# 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