Sha256: 0757b12aad7807993526c4e5bb8aedbd940da8f83679bd619c7795c6aee4927d

Contents?: true

Size: 1.36 KB

Versions: 16

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/feeds"

module Renalware
  module Feeds
    #
    # Responsible for coordinating the processing sequences of a raw HL7 message.
    #
    class MessageProcessor
      include Wisper::Publisher

      def call(raw_message)
        ActiveRecord::Base.transaction do
          message_payload = parse_message(raw_message)
          persist_message(message_payload)
          broadcast(:message_processed, message_payload)
        end
      rescue StandardError => exception
        notify_exception(exception)
        raise exception
      end

      private

      def parse_message(raw_message)
        MessageParser.new.parse(raw_message)
      end

      # If the incoming message has already been processed we should not be processing it again.
      # To help enforce this there is a unique MD5 hash on feed_messages which will baulk if the
      # same message payload is saved twice - in this case we exit #call early, the broadcast
      # is not issued and therefore the message is not processed. The message will go back into
      # the delayed_job queue and retry, failing until it finally gives up!
      def persist_message(message_payload)
        PersistMessage.new.call(message_payload)
      end

      def notify_exception(exception)
        Engine.exception_notifier.notify(exception)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
renalware-core-2.0.41 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.40 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.39 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.38 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.37 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.36 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.35 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.34 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.33 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.32 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.31 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.30 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.28 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.27 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.26 app/models/renalware/feeds/message_processor.rb
renalware-core-2.0.25 app/models/renalware/feeds/message_processor.rb