Skip to content

Instantly share code, notes, and snippets.

@tf
Created February 6, 2015 09:27
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 tf/c57e9072966712089cee to your computer and use it in GitHub Desktop.
Save tf/c57e9072966712089cee to your computer and use it in GitHub Desktop.
Resque enqueue after transaction
# Make sure no jobs are enqueued from a rolled back
# transaction.
#
# Note the after_transaction yields immediately if there is no open
# transcation.
require 'ar_after_transaction'
require 'resque'
Resque.class_eval do
class << self
alias_method :enqueue_without_transaction, :enqueue
def enqueue(*args)
if Resque.inline?
enqueue_without_transaction(*args)
else
ActiveRecord::Base.after_transaction do
enqueue_without_transaction(*args)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment