Class: MultipleMan::ModelPublisher

Inherits:
Object
  • Object
show all
Defined in:
lib/multiple_man/model_publisher.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ModelPublisher

Returns a new instance of ModelPublisher.



6
7
8
# File 'lib/multiple_man/model_publisher.rb', line 6

def initialize(options = {})
  self.options = options.with_indifferent_access
end

Instance Method Details

#publish(records, operation = :create) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/multiple_man/model_publisher.rb', line 10

def publish(records, operation=:create)
  return unless MultipleMan.configuration.enabled

  Connection.connect do |connection|
    ActiveSupport::Notifications.instrument('multiple_man.publish_messages') do
      all_records(records) do |record|
        ActiveSupport::Notifications.instrument('multiple_man.publish_message') do
          push_record(connection, record, operation)
        end
      end
    end
  end
rescue Exception => ex
  err = ProducerError.new(reason: ex, payload: records.inspect)
  MultipleMan.error(err, reraise: false)
end