Skip to content
This repository was archived by the owner on Oct 31, 2018. It is now read-only.

Repository files navigation

after_commit_queue


Rails plugin which allows to run callbacks after database transaction is committed.

What problem does it solve ?

When using state_machine it's hard to run a callback on event after the transaction is committed.

after_commit_queue plugin addresses this problem.

Installation

Add this to your Gemfile and run bundle install

gem'after_commit_queue'

Usage

Include AfterCommitQueue module in your ActiveRecord model and you're ready to go. When registering a hook with run_after_commit you can supply either a method symbol or a block. No parameter is supplied when using the block form.

classServer < ActiveRecord::Baseattr_accessor:started,:stopped# include pluginincludeAfterCommitQueuestate_machine:state,:initial=>:pendingdoafter_transition:pending=>:running,:do=>:schedule_startafter_transition:running=>:turned_off,:do=>:schedule_stopevent(:start){transition:pending=>:running}event(:stop){transition:running=>:turned_off}enddefschedule_start# Adds method to be run after transaction is committedrun_after_commit(:start_server)enddefschedule_stoprun_after_commitdostop_serverendenddefstart_server;@started=trueenddefstop_server;@stopped=trueendend

Contributions

To fetch & test the library for development, do:

$ git clone https://github.com/Ragnarson/after_commit_queue
$ cd after_commit_queue
$ bundle

Running tests

# Before each test run, the database will be created and migrated automatically
$ bundle exec rake test

If you want to contribute, please:

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Send me a pull request on Github.

This project rocks and uses MIT-LICENSE.

About

after_commit_queue allows to run callbacks after transaction is committed

Resources

Stars

41 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages