class WorkerKiller::CountLimiter

Attributes

left[R]
limit[R]
max[R]
min[R]
started_at[R]

Public Class Methods

new(min: 3072, max: 4096, verbose: false) click to toggle source
# File lib/worker_killer/count_limiter.rb, line 6
def initialize(min: 3072, max: 4096, verbose: false)
  @min = min
  @max = max
  @limit = @min + WorkerKiller.randomize(@max - @min + 1)
  @left = @limit
  @verbose = verbose
end

Public Instance Methods

check() click to toggle source
# File lib/worker_killer/count_limiter.rb, line 14
def check
  return nil if @limit <= 1

  @started_at ||= Time.now

  if @verbose
    logger.info "#{self}: worker (pid: #{Process.pid}) has #{@left} left before being limited"
  end

  return false if (@left -= 1) > 0

  logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds max number of requests (limit: #{@limit})"

  true
end
logger() click to toggle source
# File lib/worker_killer/count_limiter.rb, line 30
def logger
  WorkerKiller.configuration.logger
end