Commit d450f72c7d1fe2f0d9bf8f75657ddb7bd697a177
1 parent
6cabfd3fd7
Exists in
master
getProbeInterval() dan getProbeMaxRandomDelay()
Showing 1 changed file with 17 additions and 5 deletions Side-by-side Diff
im-probe.js
... | ... | @@ -4,8 +4,8 @@ var config; |
4 | 4 | var matrix; |
5 | 5 | var sendMessage; |
6 | 6 | |
7 | -var probeInterval = 60 * 1000; | |
8 | -var probeMaxRandomDelay = 10 * 1000; | |
7 | +var defaultProbeInterval = 60 * 1000; | |
8 | +var defaultProbeMaxRandomDelay = 10 * 1000; | |
9 | 9 | |
10 | 10 | function init(options) { |
11 | 11 | config = options.config; |
... | ... | @@ -32,8 +32,8 @@ function init(options) { |
32 | 32 | process.exit(1); |
33 | 33 | } |
34 | 34 | |
35 | - setInterval(pingAll, probeInterval); | |
36 | - logger.verbose('IM-PROBE initialized', {interval: probeInterval, maxRandomDelay: probeMaxRandomDelay}); | |
35 | + setInterval(pingAll, getProbeInterval()); | |
36 | + logger.verbose('IM-PROBE initialized', {interval: getProbeInterval(), maxRandomDelay: getProbeMaxRandomDelay()}); | |
37 | 37 | } |
38 | 38 | |
39 | 39 | function getPartnersFromString(partners) { |
... | ... | @@ -69,7 +69,7 @@ function pingAll() { |
69 | 69 | for (let i = 0; i < destinationsCount; i++) { |
70 | 70 | |
71 | 71 | let destination = destinations[i]; |
72 | - let randomDelay = Math.random() * probeMaxRandomDelay; | |
72 | + let randomDelay = Math.random() * getProbeMaxRandomDelay(); | |
73 | 73 | |
74 | 74 | setTimeout(function() { |
75 | 75 | logger.verbose('Sending probe message', {destination: destination, msg: msg}); |
... | ... | @@ -79,5 +79,17 @@ function pingAll() { |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | +function getProbeInterval() { | |
83 | + if (!config || !config.globals || !config.globals.probe_interval) { return defaultProbeInterval; } | |
84 | + return config.globals.probe_interval; | |
85 | +} | |
86 | + | |
87 | +function getProbeMaxRandomDelay() { | |
88 | + if (!config || !config.globals || !config.globals.probe_max_random_delay) { return defaultProbeInterval; } | |
89 | + return config.globals.probe_max_random_delay; | |
90 | +} | |
91 | + | |
82 | 92 | exports.init = init; |
83 | 93 | exports.getPartnersFromString = getPartnersFromString; |
94 | +exports.getProbeInterval = getProbeInterval; | |
95 | +exports.getProbeMaxRandomDelay = getProbeMaxRandomDelay; |