satya on rails
satya on rails

Reputation: 392

Rendezvous like pattern in rails

I am looking for a Rendezvous like design pattern example or implementation in Rails? Essentially looking to fire an output event only when a set of input events are all fired. In general I expect input events to trigger at different times. Here is a contrived example

Input Events : 1. Fuel Pump failure 2. Threshold in Bank 2 low 3. EV initiator inactive

Each event gets queued and when all of the input events have fired(conditions are met), a output event is fired.

A.Fuel Leak detected

Based on MVC pattern, I understand I need to implement the rendezvous pattern in the controller but want to implement it most efficiently as the volume, velocity and variability part of these events are going to be high.

Thanks Satya

Upvotes: 2

Views: 91

Answers (1)

Veraticus
Veraticus

Reputation: 16084

I'm not familiar with the rendezvous pattern in particular, but I think I would handle this in the model level with a callback. Something like this:

class Pump < ActiveRecord::Base
  before_save :check_fuel_leak

  private

  def check_fuel_leak
    Pump.fuel_leak_detected! if self.failure? && self.bank_2_threshold <= 20 && self.ev_initiator_inactive?
  end
end

A lot depends specifically on your use case though: what responds to the event that's fired? What are the actual events leading up to the output event? Still, I think this is a relatively good place to get started.

Upvotes: 1

Related Questions