Class: Renalware::Feeds::MessageProcessor
- Inherits:
-
Object
- Object
- Renalware::Feeds::MessageProcessor
- Includes:
- Broadcasting
- Defined in:
- app/models/renalware/feeds/message_processor.rb
Overview
Responsible for coordinating the processing sequences of a raw HL7 message.
Instance Attribute Summary collapse
-
#feed_message ⇒ Object
readonly
Returns the value of attribute feed_message.
-
#hl7_message ⇒ Object
readonly
Returns the value of attribute hl7_message.
-
#raw_message ⇒ Object
readonly
Returns the value of attribute raw_message.
Instance Method Summary collapse
-
#call(raw_message) ⇒ Object
We want to wrap message processing in a transaction because if message processing fails we don’t want to leave an unprocessed message in the feed_messages table.
Methods included from Broadcasting
#broadcasting_to_configured_subscribers
Instance Attribute Details
#feed_message ⇒ Object (readonly)
Returns the value of attribute feed_message.
13 14 15 |
# File 'app/models/renalware/feeds/message_processor.rb', line 13 def @feed_message end |
#hl7_message ⇒ Object (readonly)
Returns the value of attribute hl7_message.
13 14 15 |
# File 'app/models/renalware/feeds/message_processor.rb', line 13 def @hl7_message end |
#raw_message ⇒ Object (readonly)
Returns the value of attribute raw_message.
13 14 15 |
# File 'app/models/renalware/feeds/message_processor.rb', line 13 def @raw_message end |
Instance Method Details
#call(raw_message) ⇒ Object
We want to wrap message processing in a transaction because if message processing fails we don’t want to leave an unprocessed message in the feed_messages table. If we did, and the same FeedJob retires a few minutes later, if will try to save to feed_messages with the same MD5 body_hash (the message is identical to one already saved) resulting in unique key violation. Using a transaction here prevents any orphaned records if there is an error. However we should be aware that any listeners raising an error will prevent successful in all other listeners. So a listener should be careful to catch errors and not re-raise them, or use the :message_processed message (lower down) which is safer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/renalware/feeds/message_processor.rb', line 24 def call() @raw_message = ActiveRecord::Base.transaction do end rescue StandardError => exception notify_exception(exception) raise exception end |