require 'sc_core/supply_chain' require 'sc_core/message_bus' DEPLOY_ENV = (ENV["DEPLOY_ENV"] || (Object.const_defined?('DEPLOY_ENV') && DEPLOY_ENV) || LOCALHOST) module IngestionEventPublisher INGESTOR_APP_NAME = "shovel" def publish_ingestion_event entity_name, entity_type, entity_id, client_ref_id, status, bu_id, exchange_name, ingestion_comment ingestion_rules = IngestionRule.where(:bu_id => bu_id, :entity_type => entity_type, :status => status) return unless ingestion_rules.blank? headers = {'X_BU_ID' => bu_id} context = {:clientRefId => client_ref_id, :type => entity_type.underscore} publish_ingestion_event_generic entity_name, entity_id, headers, context, exchange_name end def publish_ingestion_event_generic entity_name, group_id, headers, context, exchange_name=nil exchange_name = exchange_name.blank? ? "#{SERVICE_NAME}_shovel_#{DEPLOY_ENV}" : exchange_name payload = {:entity_name => entity_name, :group_id => group_id, :headers => headers.to_json.to_s, :context => context.to_json.to_s} args = {:request_uri => "#{SupplyChain.get_url(INGESTOR_APP_NAME)}/events", :http_method => 'POST', :payload => payload.to_json, :exchange_name => exchange_name, :group_id => group_id} ScCore::MessageBus.send("shovel event for #{entity_name}", args, :async => true) end end