ryandotsmith/queue_classic_example — Issue #5: Should we use after_commit instead?
Author: gerry3
Created: 2011-11-30 03:27:46+00:00
State: open

One of our customers was having issues and we noticed that a bunch of jobs had failed because they couldn't find the record for the ID we passed in.

It looks like QC is processing the job--which we had enqueued in after_create (or after_save)--before Rails has committed the record, so it is not available for the job to find. It sounds like [this is a problem with other background job solutions](http://blog.nragaz.com/post/806739797/using-and-testing-after-commit-callbacks-in-rails-3) as well.

Here is an example of what we do instead of after_create:

after_commit :after_create_actions, :if => proc { |f| !Rails.env.test? && f.persisted? && f.new_record?}

We also do this since we use transactional tests (with RSpec):

after_create :after_create_actions, :if => proc { Rails.env.test? }

Does this make sense? Should this example app be updated to reflect this as a best practice?