All Projects → producthunt → KittyEvents

producthunt / KittyEvents

Licence: MIT license
Super simple event system on top of ActiveJob

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to KittyEvents

taskinator
A simple orchestration library for running complex processes or workflows in Ruby
Stars: ✭ 25 (+25%)
Mutual labels:  sidekiq, activejob
lambdakiq
ActiveJob on SQS & Lambda
Stars: ✭ 131 (+555%)
Mutual labels:  sidekiq, activejob
vip-git
💊 Automated "hey" · ·👋 · · of the day. Every day a unique historic event is generated based on the given day.
Stars: ✭ 4 (-80%)
Mutual labels:  events
code-of-conduct
rubyberlin.github.io/code-of-conduct/
Stars: ✭ 60 (+200%)
Mutual labels:  events
search-insights.js
Library for reporting click, conversion and view metrics using the Algolia Insights API
Stars: ✭ 39 (+95%)
Mutual labels:  events
sidekiq log analyzer
SidekiqLogAnalyser gem allows to see summary of your sidekiq workers (based on log file).
Stars: ✭ 13 (-35%)
Mutual labels:  sidekiq
vector
A high-performance observability data pipeline.
Stars: ✭ 12,138 (+60590%)
Mutual labels:  events
EventEmitter
Simple EventEmitter with multiple listeners
Stars: ✭ 19 (-5%)
Mutual labels:  events
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (+60%)
Mutual labels:  events
GETProtocolCore
🎫 Contract overview and definition of GET Protocol's NFTs
Stars: ✭ 31 (+55%)
Mutual labels:  events
event-dispatcher
💥 Best events support (symfony/event-dispatcher) to Nette Framework (@nette)
Stars: ✭ 23 (+15%)
Mutual labels:  events
ikisocket
🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io
Stars: ✭ 92 (+360%)
Mutual labels:  events
pholiday
a persian calendar holidays library for javascript
Stars: ✭ 38 (+90%)
Mutual labels:  events
vue-bus
Tiny simple central event bus plugin for Vue.js
Stars: ✭ 50 (+150%)
Mutual labels:  events
trainmanjs
TrainmanJS - Cross-Origin Communication Library
Stars: ✭ 16 (-20%)
Mutual labels:  events
berlinblockchainweek
Website for Berlin Blockchain Week 2018
Stars: ✭ 15 (-25%)
Mutual labels:  events
Timespace
A jQuery plugin to handle displaying of time events
Stars: ✭ 27 (+35%)
Mutual labels:  events
iranian-calendar-events
Fetch Iranian calendar events (Jalali, Hijri and Gregorian) from time.ir website
Stars: ✭ 28 (+40%)
Mutual labels:  events
consolidated-events
Manage multiple event handlers using few event listeners
Stars: ✭ 44 (+120%)
Mutual labels:  events
shotgun
Ready to go Rails App with TailwindCSS, ViewComponent, Devise, and more!
Stars: ✭ 25 (+25%)
Mutual labels:  sidekiq

😻 KittyEvents

Gem Version Build Status

Super simple event system built on top of ActiveJob.

KittyEvents implements the publish/subscribe pattern using ActiveJob. You setup your events and list the subscribers for them. When an event is triggered, KittyEvents will fanout the event to each of your subscribers.

Why use this

  • Uses ActiveJob. No need to add a new dependency for pub/sub.
  • Reduce complexity/establish patterns. Can be used to replace after_commit's. This creates easier to follow/read code. Less surprises = good!
  • Replace several perform_later's with a single event trigger. Reducing the amount of I/O happening in request (less I/O = faster response times)

Installation

Add this line to your application's Gemfile:

gem 'kitty_events'

And then execute:

$ bundle install

Usage

In Rails, setup your events and subscribers.

module ApplicationEvents
  extend KittyEvents

  event :user_signup, [
    WelcomeEmailWorker,
    WelcomeTweetWorker,
    SyncProfileImageWorker,
    ExampleWorker.set(wait: 5.minutes), # standard ActiveJob settings work as well!
  ]

  event :user_upvote, [
    SomeWorker,
    AnotherWorker,
  ]
end

You can put this in app/workers or similar folder.

Each subscriber must be an ActiveJob and respond to perform_later(object).

class ExampleWorker < ActiveJob::Base
  def perform(user)
    # do work
  end
end

Then in your application, to trigger an event. Do the following.

ApplicationEvents.trigger(:user_signup, user)

Using the above example, triggering this event would pass user to each of the subscribers defined in our initializer:

WelcomeEmailWorker,
WelcomeTweetWorker,
SyncProfileImageWorker,
ExampleWorker.set(wait: 5.minutes)

Worker Configuration

The worker is configurable via the initializer. Here are examples for catching errors and setting the queue.

# config/initializers/application_events.rb
module ApplicationEvents
  extend KittyEvents

  event :user_signup, [
    WelcomeEmailWorker,
    WelcomeTweetWorker,
  ]

  handle_worker.rescue_from ActiveJob::DeserializationError do |exception|
    # handle deserialization errors
  end

  handle_worker.queue_as :events # use a specific queue
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. 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 tags, and push the .gem file to rubygems.org.

Contributing

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

License

Product Hunt

 _________________
< The MIT License >
 -----------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].