Last active
August 29, 2015 14:01
-
-
Save YanhaoYang/c71fbb00c2c28233fda6 to your computer and use it in GitHub Desktop.
If a Rails server is running in single threading mode, you can begin a transaction by a request / action, then end a transaction with another request / action. All requests between these two requests will be wrapped in one transaction. How can this be useful? Sometimes.
This file contains hidden or 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
module Concerns | |
module Transactions | |
extend ActiveSupport::Concern | |
def transaction_begin | |
ActiveRecord::Base.connection.begin_db_transaction | |
ActiveRecord::Base.connection.increment_open_transactions | |
render nothing: true | |
end | |
def transaction_rollback | |
ActiveRecord::Base.connection.decrement_open_transactions | |
ActiveRecord::Base.connection.rollback_db_transaction | |
render nothing: true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment