GithubHelp home page GithubHelp logo

after_transaction_commit's Introduction

After Transaction Commit

ActiveRecord::Base.connection.after_transaction_commit { ... }

Build Status

An ActiveRecord extension that allows writing callbacks to run after the current transaction commits. This is similar to the built-in ActiveRecord::Base#after_commit functionality, but more flexible, and doesn't require putting the callback on a specific model.

Callbacks will only run once, on the next commit, not after every subsequent commit. Callbacks will never run if the transaction rolls back.

Installation

Add this line to your application's Gemfile:

gem 'after_transaction_commit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install after_transaction_commit

Usage

ActiveRecord::Base.transaction do
  ActiveRecord::Base.connection.after_transaction_commit { run_some_background_job }
  # run_some_background_job has not run yet
end
# now, it has run

# this one runs immediately, since we are outside a transaction
ActiveRecord::Base.connection.after_transaction_commit { some_other_task }

Usage in Tests

If you want to write tests that interact with after_transaction_commit callbacks, pull in the test_after_commit gem in your test environment, and things will work as expected. See that gem's README for installation instructions.

Contributing

  1. Fork it ( https://github.com/instructure/after_transaction_commit/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

after_transaction_commit's People

Contributors

ccutrer avatar codekitchen avatar simonista avatar tierra avatar wollistik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

after_transaction_commit's Issues

Release of Version 2.2.2

Hi, I saw you have already merged a PR for Rails 6.1 compatibility. Is there any other issue you want to resolve or what is preventing you from releasing version 2.2.2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.