-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When monitoring a script, it's handy to limit the maximum number of restart. But it's not the same if the script fails 10 times in 10 seconds and 10 times in 10 weeks. On the first case, there is probably an hard error and it's better to stop soon trying to restart this script. But on the second case, a max of 10 is not enough. Maybe it's just a crontab running once a week that makes it fail. The cooldownInterval is here to make max time sensitive. Forever-monitor keeps a counter with the number of failures of the script. When this counter reaches the max, it stops trying to restart it. With cooldownInterval, this counter is halfed at a regular interval defined by the number of seconds of cooldownInterval. For example, with cooldownInterval=300, if the counter is at 4 failures and in the next 5 minutes, the script won't fail, it will go to 2. And if the next 5 following minutes, it still run quiet, it will go to 1. And 5 more minutes, and will be reset to 0.
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* watch.js: Plugin for `Monitor` instances which decreases the count of | ||
* failures over time. It makes the max option time sensitive (ie it's not the | ||
* same to have 10 failures in 10 seconds and 10 failures in 10 weeks). | ||
* | ||
* (C) 2010 Charlie Robbins & the Contributors | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
// | ||
// Name the plugin | ||
// | ||
exports.name = 'cooldown'; | ||
|
||
// | ||
// ### function attach (options) | ||
// #### @options {Object} Options for attaching to `Monitor` | ||
// | ||
// Attaches functionality for logging stdout and stderr to `Monitor` instances. | ||
// | ||
exports.attach = function (options) { | ||
var monitor = this; | ||
|
||
setInterval(function() { | ||
monitor.times = Math.floor(monitor.times / 2); | ||
}, options.cooldownInterval * 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var assert = require('assert') | ||
path = require('path'), | ||
vows = require('vows'), | ||
fmonitor = require('../../lib'), | ||
macros = require('../helpers/macros'); | ||
|
||
var examplesDir = path.join(__dirname, '..', '..', 'examples'); | ||
|
||
vows.describe('forever-monitor/plugins/logger').addBatch({ | ||
'When using the cooldown plugin': { | ||
'running error-on-timer sample one hundred times': { | ||
topic: function () { | ||
var script = path.join(examplesDir, 'error-on-timer.js'); | ||
var options = { | ||
max: 10, | ||
cooldownInterval: 1, | ||
silent: true, | ||
outFile: 'test/fixtures/stdout.log', | ||
errFile: 'test/fixtures/stderr.log', | ||
args: [] | ||
} | ||
var child = new (fmonitor.Monitor)(script, options); | ||
setTimeout(this.callback.bind({}, null, child), 2100); | ||
child.start(); | ||
}, | ||
'should have not reached max': function (err, child) { | ||
assert.ok(child.times < 10); | ||
} | ||
}, | ||
'running error-on-timer sample three times': macros.assertTimes( | ||
path.join(examplesDir, 'error-on-timer.js'), | ||
3, | ||
{ | ||
cooldownInterval: 10, | ||
minUptime: 200, | ||
silent: true, | ||
outFile: 'test/fixtures/stdout.log', | ||
errFile: 'test/fixtures/stderr.log', | ||
args: [] | ||
} | ||
) | ||
} | ||
}).export(module); |