Created
February 6, 2015 09:27
-
-
Save tf/c57e9072966712089cee to your computer and use it in GitHub Desktop.
Resque enqueue after transaction
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
# 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