Warning: this is under active development!
This gem aims to provide the following tools to augment your ActiveRecord & Sidekiq stack.
- Barebones event API through Sidekiq to publish whatever you want
- Database-driven API to manage subscribers so that users may rewire whatever you let them (transactional emails, campaigns, etc...)
- Static/Code-driven API to subscribe a basic ruby block to an event.
- A new communication pattern between your ActiveRecord models that runs asynchronously through Sidekiq. a. describe model lifecycle events and callbacks with class-level helper methods/DSL
Add this line to your application's Gemfile:
gem 'reactor'
And then execute:
$ bundle
Or install it yourself as:
$ gem install reactor
Well, this is evolving, so it's probably best to go read the specs.
Reactor::Event.publish(:event_name, any: 'data', you: 'want')
Describe lifecycle events like so
publishes :my_model_created
publishes :state_has_changed, if: -> { state_has_changed? }
You can now bind any block to an event in your models like so
on_event :any_event do |event|
event.target.do_something_about_it!
end
Static subscribers like these are automatically placed into Sidekiq and executed in the background
It's also possible to run a subscriber block in memory like so
on_event :any_event, in_memory: true do |event|
event.target.do_something_about_it_and_make_the_user_wait!
end
Calling Reactor.test_mode!
enables test mode. (You should call this as early as possible, before your subscriber classes
are declared). In test mode, no subscribers will fire unless they are specifically enabled, which can be accomplished
by calling
Reactor.enable_test_mode_subscriber(MyAwesomeSubscriberClass)
We also provide
Reactor.with_subscriber_enabled(MyClass) do
# stuff
end
for your testing convenience.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Hired is a marketplace for top engineering talent to find full-time technology jobs. Talented Ruby developers (like yourself) are in extremely high demand! On Hired, apply once and receive 5 to 15 competing job offers in one week from 800+ technology companies. Average Ruby engineer salaries on Hired are around $120,000 per year!
We are Ruby developers ourselves, and we use all of our open source projects in production. We always encourge forks, pull requests, and issues. Get in touch with the Hired Engineering team at [email protected].