All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- I18n support: preserve
I18n.localesetting from whenafter_commitis called and restore it for callback execution. Pull request #36 by Bilka2
-
Ability to propagate exception for multiple
after_commitcallbacks within transaction. Should handle exception inside callback to avoid stopping other callbacks.Pull request #35 by @kevink1103. Also see discussion at #34.
-
Ability to prepend callbacks to the head of callback queue using
prepend: trueoption.AfterCommitEverywhere.after_commit { puts "I'm second!" } AfterCommitEverywhere.after_commit(prepend: true) { puts "I'm first!" }
See Pull request #30 by @quentindemetz and @A1090.
-
Don't include development-related files into packaged gem to avoid confusing users or software tools. @Envek.
See discussion at #26.
Files packaged after this change:
CHANGELOG.md LICENSE.txt README.md after_commit_everywhere.gemspec lib/after_commit_everywhere.rb lib/after_commit_everywhere/version.rb lib/after_commit_everywhere/wrap.rb
-
in_transactionhelper method to execute code within existing transaction or start a new one if there is no tx open.It is similar to
ActiveRecord::Base.transaction, but it doesn't swallowActiveRecord::Rollbackexception in case when there is no transaction open.See discussion at #23 for details.
-
Ability to call
in_transactionhelper with the same arguments asActiveRecord::Base.transaction. @Envek.
-
Connection leak from the connection pool when
after_commitcalled outside Rails executor without connection checked out and some connections were already checked out from another threads.See discussion at issue #20 for details.
-
Connection leak from the connection pool when
after_commitcalled outside Rails executor without connection checked outUsually all invocations of
after_commit(whether it happens during serving HTTP request in Rails controller or performing job in Sidekiq worker process) are made inside Rails executor which checks in any connections back to the connection pool that were checked out inside its block.However, in cases when a)
after_commitwas called outside of Rails executor (3-rd party gems or non-Rails apps using ActiveRecord) and b) database connection hasn't been checked out yet, then connection will be checked out byafter_commitimplicitly by call toActiveRecord::Base.connectionand not checked in back afterwards causing it to leak from the connection pool.But in that case we can be sure that there is no transaction in progress ('cause one need to checkout connection and issue
BEGINto it), so we don't need to check it out at all and can fast-forward towithout_txaction.See discussion at issue #20 for details.
-
Allow to change callbacks' behavior when they are called outside transaction:
AfterCommitEverywhere.after_commit(without_tx: :raise) do # Will be executed only if was called within transaction # Error will be raised otherwise end
Available values for
without_txkeyword argument::executeto execute callback immediately:warn_and_executeto print warning and execute immediately:raiseto raise an exception instead of executing
-
Allow to call transactional callbacks directly on
AfterCommitEverywheremodule:AfterCommitEverywhere.after_commit { puts "If you see me then transaction has been successfully commited!" }
-
Allow to call
in_transaction?helper method from instance methods in classes that includesAfterCommitEverywheremodule.
Declare gem as stable. No changes since 0.1.5.
See #11 for discussion.
- [PR #8] Callback registration when callback methods are aliased. (@stokarenko)
- [PR #6] ActiveRecord 6.0 compatibility. (@joevandyk)
- Make
in_transaction?helper method public. (@Envek)
- Do not issue warning on
after_commitinvocation outside of transaction as it is expected behaviour. (@Envek)
- Initial version with
after_commit,before_commit. andafter_rollbackcallbacks. (@Envek)