Class: WorkerKiller::CountLimiter
- Inherits:
-
Object
- Object
- WorkerKiller::CountLimiter
- Defined in:
- lib/worker_killer/count_limiter.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(min: 3072, max: 4096, verbose: false) ⇒ CountLimiter
constructor
A new instance of CountLimiter.
- #logger ⇒ Object
Constructor Details
#initialize(min: 3072, max: 4096, verbose: false) ⇒ CountLimiter
Returns a new instance of CountLimiter.
6 7 8 9 10 11 12 |
# File 'lib/worker_killer/count_limiter.rb', line 6 def initialize(min: 3072, max: 4096, verbose: false) @min = min @max = max @limit = nil @left = nil @verbose = verbose end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
4 5 6 |
# File 'lib/worker_killer/count_limiter.rb', line 4 def left @left end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/worker_killer/count_limiter.rb', line 4 def limit @limit end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/worker_killer/count_limiter.rb', line 4 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
4 5 6 |
# File 'lib/worker_killer/count_limiter.rb', line 4 def min @min end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
4 5 6 |
# File 'lib/worker_killer/count_limiter.rb', line 4 def started_at @started_at end |
Instance Method Details
#check ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/worker_killer/count_limiter.rb', line 14 def check # initialize limits on first check if @limit.nil? @limit = min + WorkerKiller.randomize(max - min + 1) @left = @limit end return nil if @limit < 1 @started_at ||= Time.now if @verbose logger.info "#{self.class}: worker (pid: #{Process.pid}) has #{@left} left before being limited" end return false if (@left -= 1) > 0 logger.warn "#{self.class}: worker (pid: #{Process.pid}) exceeds max number of requests (limit: #{@limit})" true end |
#logger ⇒ Object
36 37 38 |
# File 'lib/worker_killer/count_limiter.rb', line 36 def logger WorkerKiller.configuration.logger end |