Class: Dionysus::Producer::Outbox::RecordsProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/dionysus/producer/outbox/records_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(config: Dionysus::Producer.configuration) ⇒ RecordsProcessor

Returns a new instance of RecordsProcessor.



7
8
9
# File 'lib/dionysus/producer/outbox/records_processor.rb', line 7

def initialize(config: Dionysus::Producer.configuration)
  @config = config
end

Instance Method Details

#call(records) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dionysus/producer/outbox/records_processor.rb', line 11

def call(records)
  failed_records = []
  records_to_publish = resolve_records_to_publish(records)
  records_to_publish.each do |record|
    begin
      publish(record)
    rescue => e
      record.handle_error(e)
      record.save!
      failed_records << record
    end
    yield record if block_given?
  end
  published_records = records - failed_records
  mark_as_published(published_records)
  records
end