Skip to content

Commit

Permalink
Add loggers to track broker updates to EDI
Browse files Browse the repository at this point in the history
  • Loading branch information
jayreddy519 committed Jun 25, 2024
1 parent 055fffe commit 9370be3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/models/listeners/enrollment_broker_updated_listener.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module Listeners
class EnrollmentBrokerUpdatedListener < Amqp::RetryClient
def initialize
@logger = Logger.new("#{Rails.root}/log/enrollment_broker_updated_listener.log")
end

def self.queue_name
ec = ExchangeInformation
Expand Down Expand Up @@ -45,33 +42,32 @@ def on_message(delivery_info, properties, body)
end
channel.ack(delivery_info.delivery_tag, false)
rescue => error
@logger.error("Exception occurred: #{error.message}")
@logger.error(error.backtrace.join("\n"))
Rails.logger.info("Exception occurred: #{error.message} for policy: #{policy.eg_id}")
resource_error_broadcast("exception", "500", error.backtrace, properties.headers)
channel.reject(delivery_info.delivery_tag, false)
end
end

def update_broker_on_policy(broker_id, policy)
@logger.info("Starting update_broker_on_policy for policy: #{policy.id} && broker: #{broker_id}")
Rails.logger.info("Starting update_broker_on_policy for policy: #{policy.eg_id} && broker: #{broker_id}")
if policy.broker_id != broker_id
policy.broker_id = broker_id
policy.save!
@logger.info("Started publishing policy: #{policy.id} to edi")
Rails.logger.info("Started publishing policy: #{policy.eg_id} to edi")
publish_to_edi(policy)
@logger.info("Finished publishing policy: #{policy.id} to edi")
Rails.logger.info("Finished publishing policy: #{policy.eg_id} to edi")
end
end

def publish_to_edi(policy)
@logger.info("Starting publish_to_edi for policy: #{policy.id}")
Rails.logger.info("Starting publish_to_edi for policy: #{policy.eg_id}")
member = policy.subscriber.person.authority_member
af = ::BusinessProcesses::AffectedMember.new({
:policy => policy
}.merge({"member_id" => member.hbx_member_id, "gender" => member.gender}))
ict = ChangeSets::IdentityChangeTransmitter.new(af, policy, "urn:openhbx:terms:v1:enrollment#change_broker")
ict.publish
@logger.info("Finished publishing to edi for policy: #{policy.id}")
Rails.logger.info("Finished publishing to edi for policy: #{policy.id}")
end

def self.create_queues(chan)
Expand Down

0 comments on commit 9370be3

Please sign in to comment.