Skip to content

Yael is Yet Another Event Library based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.

Notifications You must be signed in to change notification settings

nerdgeschoss/yael

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yael

Yael is Yet Another Event Library based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.

Usage

Define your routes in config/events.rb like this:

Yael::Bus.shared.routing do
  dispatch :order_confirmed, to: "order_mailer.confirm", delay: 5.minutes, queue: :low_priority
  dispatch :order_confirmed, to: "slack"
end

Now include the publisher in your class and dispatch events:

class Order < ApplicationRecord
  include Yael::Publisher

  def confirm_order
    publish :order_confirmed, ip: some_id, some_other_data: data
  end
end

class Slack
  def self.on_order_confirmed(ip:)
    # send a notification to slack
  end
end

Calling confirm_order now will invoke OrderMailer.confirm and Slack.notify_order.

You can also request historical events of an object: Yael::Event.for(Order.find(id)) will return all events recorded.

Some Things to Keep in Mind

  • the subscriber signature does not have to exactly match the published payload - yael will return all matching parameters
  • everything is executed asynchronously inside of a job, even dispatching events
  • you can not only publish from ActiveRecord models, but from any class by providing a stream name: Yael::Bus.shared.dispatch(:event_name, stream: "my_stream", payload: {})

Installation

Add this line to your application's Gemfile:

gem 'yael'

And then execute:

bundle install

Generate a migration for your database:

rails generate yael:install
rails db:migrate

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yael. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Yael project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Yael is Yet Another Event Library based on top of ActiveJob. It helps you dispatching events asynchronously in your code base and react to them just like routing in Rails.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages