class CountPublisher

Constants

INCREMENT_SIZE

Public Class Methods

new(redis_row_count) click to toggle source
# File lib/count_publisher.rb, line 4
def initialize(redis_row_count)
  @redis_row_count = redis_row_count
  @redis = Redis.current
end

Public Instance Methods

callbacks() click to toggle source
# File lib/count_publisher.rb, line 9
def callbacks
  { during_execute: publish_ongoing, after_execute: expire_count }
end

Private Instance Methods

expire_count() click to toggle source
# File lib/count_publisher.rb, line 23
def expire_count
  ->(_row_count) { @redis_row_count.expire }
end
publish_ongoing() click to toggle source
# File lib/count_publisher.rb, line 15
def publish_ongoing
  lambda do |_row, row_count|
    if row_count % INCREMENT_SIZE == 0
      @redis_row_count.increment_count_by(INCREMENT_SIZE)
    end
  end
end