Class: MdliveShared::EventNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/mdlive_shared/event_notifier.rb

Constant Summary collapse

EVENT_NAMES =
{
  "patient:logged_in" => 1,
  "patient:created" => 1,
  "consultation:scheduled" => 1,
  "consultation:completed" => 1,
  "eligible_member:imported" => 1,
  "signup_url:created" => 1,
  "provider:waiting_room_changed" => 1,
  "provider:avail_changed" => 1,
  "provider:consult_list_changed" => 1,
  "provider:profile_changed" => 1,
  "message:created" => 1
}.freeze
ATTRIBUTES_FOR_EVENTS =
{
  "patient:created" => [ :id ],
  "patient:logged_in" => [ :id ],
  "consultation:scheduled" => [ :id ],
  "consultation:completed" => [ :id ],
  "eligible_member:imported" => [ :id ],
  "signup_url:created" => [ :id ],
  "provider:waiting_room_changed" => [:cocq_id],
  "provider:avail_changed" => [:provider_id],
  "provider:consult_list_changed" => [:provider_id],
  "provider:profile_changed" => [:provider_id],
  "message:created" => [:msg_id]
}.freeze

Class Method Summary collapse

Class Method Details

.attributes_for_eventsObject



57
58
59
# File 'lib/mdlive_shared/event_notifier.rb', line 57

def self.attributes_for_events
  ATTRIBUTES_FOR_EVENTS
end

.event(event, attrs, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mdlive_shared/event_notifier.rb', line 32

def self.event(event, attrs, opts={})
  event_names.fetch(event)
  attrs = JSON.parse(attrs.to_json)
  attrs = attributes_for_events.fetch(event).inject({}) do |hsh, attr|
    hsh[attr] = attrs.fetch(attr.to_s)
    hsh
  end
  with_exchange(event) do |exchange|
    exchange.publish(attrs.to_json, opts)
  end
end

.event_namesObject



53
54
55
# File 'lib/mdlive_shared/event_notifier.rb', line 53

def self.event_names
  EVENT_NAMES
end

.with_exchange(event) {|conn.create_channel.fanout(event, :durable => true)| ... } ⇒ Object

Yields:

  • (conn.create_channel.fanout(event, :durable => true))


44
45
46
47
48
49
50
51
# File 'lib/mdlive_shared/event_notifier.rb', line 44

def self.with_exchange(event)
  conn = Bunny.new(AMQ::Settings.parse_amqp_url(ENV.fetch("RABBIT_MQ_URL")), 
                   :read_timeout => 25, 
                   :connection_timeout => 25)
  conn.start
  yield(conn.create_channel.fanout(event, :durable => true))
  conn.close
end