Skip to content

Commit

Permalink
add loggers to track broker updates to EDI (#212)
Browse files Browse the repository at this point in the history
* Add loggers to track broker updates to EDI

* Add loggers to track broker updates to EDI
  • Loading branch information
jayreddy519 authored Jun 25, 2024
1 parent 654eacf commit d7db218
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/listeners/enrollment_broker_updated_listener.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module Listeners
class EnrollmentBrokerUpdatedListener < Amqp::RetryClient

def self.queue_name
ec = ExchangeInformation
"#{ec.hbx_id}.#{ec.environment}.q.glue.enrollment_broker_updated_listener"
end

def resource_event_broadcast(level, event_key, r_code, body = "", other_headers = {})
event_body = (body.respond_to?(:to_s) ? body.to_s : body.inspect)
Rails.logger.info("Start broadcast_event: event_body = #{event_body}, level = #{event_key}, level = #{level}, r_code=#{r_code}")
broadcast_event({
:routing_key => "#{level}.application.glue.enrollment_broker_updated_listener.#{event_key}",
:headers => other_headers.merge({
Expand Down Expand Up @@ -41,26 +43,32 @@ def on_message(delivery_info, properties, body)
end
channel.ack(delivery_info.delivery_tag, false)
rescue => error
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)
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!
Rails.logger.info("Started publishing policy: #{policy.eg_id} to edi")
publish_to_edi(policy)
Rails.logger.info("Finished publishing policy: #{policy.eg_id} to edi")
end
end

def publish_to_edi(policy)
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
Rails.logger.info("Finished publishing to edi for policy: #{policy.id}")
end

def self.create_queues(chan)
Expand Down Expand Up @@ -107,4 +115,4 @@ def self.run
conn.close
end
end
end
end

0 comments on commit d7db218

Please sign in to comment.