Class: LogStash::Inputs::Snmp::StoppableIntervalRunner
- Inherits:
-
Object
- Object
- LogStash::Inputs::Snmp::StoppableIntervalRunner
- Defined in:
- lib/logstash/inputs/snmp.rb
Overview
The StoppableIntervalRunner is capable of running a block of code at a repeating interval, while respecting the stop condition of the plugin.
Instance Method Summary collapse
-
#every(interval_seconds, desc = "operation") { ... } ⇒ Object
Runs the provided block repeatedly using the provided interval.
-
#initialize(plugin) ⇒ StoppableIntervalRunner
constructor
A new instance of StoppableIntervalRunner.
- #sleep(duration) ⇒ Object private
Constructor Details
#initialize(plugin) ⇒ StoppableIntervalRunner
Returns a new instance of StoppableIntervalRunner.
335 336 337 |
# File 'lib/logstash/inputs/snmp.rb', line 335 def initialize(plugin) @plugin = plugin end |
Instance Method Details
#every(interval_seconds, desc = "operation") { ... } ⇒ Object
Runs the provided block repeatedly using the provided interval. After executing the block, the remainder of the interval if any is slept off using an interruptible sleep. If no time remains, a warning is emitted to the logs.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/logstash/inputs/snmp.rb', line 348 def every(interval_seconds, desc="operation", &block) until @plugin.stop? start_time = Time.now yield duration_seconds = Time.now - start_time if duration_seconds >= interval_seconds @plugin.logger.warn("#{desc} took longer than the configured interval", :interval_seconds => interval_seconds, :duration_seconds => duration_seconds.round(3)) else remaining_interval = interval_seconds - duration_seconds sleep(remaining_interval) end end end |
#sleep(duration) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
365 366 367 |
# File 'lib/logstash/inputs/snmp.rb', line 365 def sleep(duration) Stud.stoppable_sleep(duration) { @plugin.stop? } end |