Class: Sidekiq::HerokuAutoscale::PollInterval
- Inherits:
-
Object
- Object
- Sidekiq::HerokuAutoscale::PollInterval
- Defined in:
- lib/sidekiq/heroku_autoscale/poll_interval.rb
Instance Method Summary collapse
- #call(process) ⇒ Object
-
#initialize(method_name, before_update: 0, after_update: 0) ⇒ PollInterval
constructor
A new instance of PollInterval.
- #poll! ⇒ Object
Constructor Details
#initialize(method_name, before_update: 0, after_update: 0) ⇒ PollInterval
Returns a new instance of PollInterval.
5 6 7 8 9 10 |
# File 'lib/sidekiq/heroku_autoscale/poll_interval.rb', line 5 def initialize(method_name, before_update: 0, after_update: 0) @method_name = method_name @before_update = before_update @after_update = after_update @requests = {} end |
Instance Method Details
#call(process) ⇒ Object
12 13 14 15 16 |
# File 'lib/sidekiq/heroku_autoscale/poll_interval.rb', line 12 def call(process) return unless process @requests[process.name] ||= process poll! end |
#poll! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sidekiq/heroku_autoscale/poll_interval.rb', line 18 def poll! @thread ||= Thread.new do begin while @requests.size > 0 sleep(@before_update) if @before_update > 0 @requests.reject! { |n, p| p.send(@method_name) } sleep(@after_update) if @after_update > 0 end ensure @thread = nil end end end |