lib/riemann/babbler/plugin.rb in riemann-babbler-2.8.1 vs lib/riemann/babbler/plugin.rb in riemann-babbler-2.8.2
- old
+ new
@@ -150,23 +150,22 @@
end
# Main method
def run!
return 0 unless run_plugin
- t0 = Time.now
+ sleep Random.new.rand(10)
loop do
-
+ t_start = Time.now
begin
- Timeout::timeout(plugin.interval) { tick }
+ Timeout::timeout(plugin.interval.to_f * 2/3 ) { tick }
rescue TimeoutError
plugin_error!('Timeout plugin execution')
rescue => e
plugin_error!("Plugin '#{plugin_name}' has a error.\n #{e.class}: #{e}\n #{e.backtrace.join("\n")}")
else
plugin_no_error!
end
-
- sleep(plugin.interval - ((Time.now - t0) % plugin.interval))
+ sleep(plugin.interval - (Time.now - t_start).to_i)
end
end
end