Class: Saseo::Publishing::Publisher
- Inherits:
-
Object
- Object
- Saseo::Publishing::Publisher
- Defined in:
- lib/saseo/publishing/publisher.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
- #logger ⇒ Object
Instance Method Summary collapse
-
#initialize(batch_size: nil) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish_batch ⇒ Object
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_size ⇒ Object
Returns the value of attribute batch_size.
10 11 12 |
# File 'lib/saseo/publishing/publisher.rb', line 10 def batch_size @batch_size end |
#logger ⇒ Object
18 19 20 |
# File 'lib/saseo/publishing/publisher.rb', line 18 def logger @logger ||= Logger.new(STDOUT) end |
Instance Method Details
#publish_batch ⇒ Object
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 |