Class: Saseo::Publishing::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/saseo/publishing/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(batch_size: nil) ⇒ Publisher

Returns a new instance of Publisher.



13
14
15
16
# File 'lib/saseo/publishing/publisher.rb', line 13

def initialize(batch_size: nil)
  batch_size      ||= Saseo.config.publisher_batch_size
  self.batch_size = batch_size
end

Instance Attribute Details

#batch_sizeObject

Returns the value of attribute batch_size.



10
11
12
# File 'lib/saseo/publishing/publisher.rb', line 10

def batch_size
  @batch_size
end

#loggerObject



18
19
20
# File 'lib/saseo/publishing/publisher.rb', line 18

def logger
  @logger ||= Logger.new(STDOUT)
end

Instance Method Details

#publish_batchObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/saseo/publishing/publisher.rb', line 22

def publish_batch
  Saseo::Models::Source::Version.transaction do
    ids = []
    Saseo::Models::Source::Version.lock.limit(batch_size).each do |record|
      Saseo::Publishing::DataChangeMessage.publish(record)
      logger.debug { "published source version: #{record.id}" }
      ids << record.id
    end
    Saseo::Models::Source::Version.delete_all(id: ids)
    logger.debug { "deleted source versions: #{ids.count}" } if ids.count > 0

  end
rescue => e
  logger.error { "Saseo publishing error: #{e.class} - #{e.message} at #{e.backtrace}" }
end