Sha256: eb081031360e4d9e22ffef7e95f58b25da1f58ce936ea6d6b362aeb9af61ef67

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

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

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
apl-library-0.0.90 lib/apl-library/ingestion_event_publisher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/lib/apl-library/ingestion_event_publisher.rb