Reactor

A Sidekiq-driven pub/sub layer for your ruby app

View on GitHub

Hired was written with “log every relevant user click for analysis later” in mind from day one. It began as little ActiveRecord::Base#create calls sprinkled across the controller layer like so:

def create
  employment = Employment.new params[:employment]
  if employment.save
    action_event :employment_created
    redirect_to profile_path
  else
    render :new
  end
end

def action_event(name, options)
  Activity.create options.merge(actor: current_user, type: name.to_s.camelize)
end

Each of these lines was refactored to pass through a new pub/sub layer that would allow us to bind arbitrary blocks of code and database-driven transactional emails as well as create a log of the activity.

def action_event(name, options)
  Reactor::Event.publish name, options.merge(actor: current_user)
end

Read the full story in this blog post.

Pros

Cons