Class: EventSender

Inherits:
Object
  • Object
show all
Defined in:
app/models/event_sender.rb

Class Method Summary collapse

Class Method Details

.format_message(hash) ⇒ Object

format message expected output <?xml version='1.0'?> <event> <message>win</message> <eventful_id>123</eventful_id> <eventful_type>Request</eventful_type> <descriptor_key>failure</descriptor_key> <content>fail</content> <family>fail</family> <identifier>123</identifier> </event>


13
14
15
16
# File 'app/models/event_sender.rb', line 13

def self.format_message(hash)
  doc = hash.to_xml(root: 'event', skip_types: true)
  doc.to_s.tr!('-', '_').gsub!('UTF_8', 'UTF-8')
end

.send_cancel_event(request_id, reason, comment, options = nil) ⇒ Object


22
23
24
# File 'app/models/event_sender.rb', line 22

def self.send_cancel_event(request_id, reason, comment, options = nil)
  send_state_event('cancel', request_id, reason, comment, batch_id, nil, options)
end

.send_fail_event(request_id, reason, comment, batch_id, user = nil, options = nil) ⇒ Object


18
19
20
# File 'app/models/event_sender.rb', line 18

def self.send_fail_event(request_id, reason, comment, batch_id, user = nil, options = nil)
  send_state_event('fail', request_id, reason, comment, batch_id, user, options)
end

.send_pass_event(request_id, reason, comment, batch_id, user = nil, options = nil) ⇒ Object


26
27
28
# File 'app/models/event_sender.rb', line 26

def self.send_pass_event(request_id, reason, comment, batch_id, user = nil, options = nil)
  send_state_event('pass', request_id, reason, comment, batch_id, user, options)
end

.send_pick_event(well_id, purpose_name, message, options = nil) ⇒ Object


40
41
42
43
# File 'app/models/event_sender.rb', line 40

def self.send_pick_event(well_id, purpose_name, message, options = nil)
  hash = { eventful_id: well_id, eventful_type: 'Asset', family: PlatesHelper::event_family_for_pick(purpose_name), message: message, content: Date.today.to_s }
  publishing_to_queue(hash.merge(options || {}))
end

.send_request_update(request_id, family, message, options = nil) ⇒ Object


35
36
37
38
# File 'app/models/event_sender.rb', line 35

def self.send_request_update(request_id, family, message, options = nil)
  hash = { eventful_id: request_id, eventful_type: 'Request', family: family, message: message }
  publishing_to_queue(hash.merge(options || {}))
end

.send_state_event(state, request_id, reason, comment, batch_id, user = nil, options = nil) ⇒ Object


30
31
32
33
# File 'app/models/event_sender.rb', line 30

def self.send_state_event(state, request_id, reason, comment, batch_id, user = nil, options = nil)
  hash = { eventful_id: request_id, eventful_type: 'Request', family: state, content: reason, message: comment, identifier: batch_id, created_by: user }
  publishing_to_queue(hash.merge(options || {}))
end