From 51f4c2d0ba810c97000c3f5db37b198938683c13 Mon Sep 17 00:00:00 2001 From: Adam Winberg Date: Fri, 27 May 2016 13:00:25 +0200 Subject: Added feature to disable polling based on interval --- lib/oxidized/jobs.rb | 3 +++ lib/oxidized/worker.rb | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index 2c656f6..719bda9 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -6,6 +6,9 @@ module Oxidized def initialize max, interval, nodes @max = max + # Set interval to 1 if interval is 0 (=disabled) so we don't break + # the 'ceil' function + @interval = 1 if @interval == 0 @interval = interval @nodes = nodes @last = Time.now.utc diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index 324dcb5..48852ef 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -18,7 +18,9 @@ module Oxidized # ask for next node in queue non destructive way nextnode = @nodes.first unless nextnode.last.nil? - break if nextnode.last.end + Oxidized.config.interval > Time.now.utc + # Set unobtainable value for 'last' if interval checking is disabled + last = Oxidized.config.interval == 0 ? Time.now.utc + 10 : nextnode.last.end + break if last + Oxidized.config.interval > Time.now.utc end # shift nodes and get the next node node = @nodes.get -- cgit v1.2.1 From 71290cf4f0b866557fe0f87bbace898fdc1c2ca3 Mon Sep 17 00:00:00 2001 From: Adam Winberg Date: Fri, 27 May 2016 13:05:19 +0200 Subject: Use better variable declaration --- lib/oxidized/jobs.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index 719bda9..b61a54d 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -8,8 +8,7 @@ module Oxidized @max = max # Set interval to 1 if interval is 0 (=disabled) so we don't break # the 'ceil' function - @interval = 1 if @interval == 0 - @interval = interval + @interval = @interval == 0 ? 1 : interval @nodes = nodes @last = Time.now.utc @durations = Array.new @nodes.size, AVERAGE_DURATION -- cgit v1.2.1 From 2d8e9087fa7ca25fcb46eb8b9e20a7ddf0293ec1 Mon Sep 17 00:00:00 2001 From: Adam Winberg Date: Fri, 27 May 2016 13:09:16 +0200 Subject: Fix syntax --- lib/oxidized/jobs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index b61a54d..c566778 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -8,7 +8,7 @@ module Oxidized @max = max # Set interval to 1 if interval is 0 (=disabled) so we don't break # the 'ceil' function - @interval = @interval == 0 ? 1 : interval + @interval = interval == 0 ? 1 : interval @nodes = nodes @last = Time.now.utc @durations = Array.new @nodes.size, AVERAGE_DURATION -- cgit v1.2.1