Permalink
Browse files

Merge pull request #43 from chamerling/master

Local Heartbeat
  • Loading branch information...
2 parents feb5834 + 7a42352 commit 893130f6ec7d56c7435dbb0121dba8e2d451739f @obazoud obazoud committed Jan 24, 2013
Showing with 38 additions and 0 deletions.
  1. +34 −0 plugins/heartbeat/heartbeat_plugin.js
  2. +4 −0 settings.js
@@ -0,0 +1,34 @@
+//
+// Periodically call the healtcheck HTTP URL.
+// This can be used on some Cloud providers to keep the app alive...
+//
+// For example, to keep the app alive on Heroku:
+//
+// 1. Deploy your app
+// 2. Get the Heroku URL of your app
+// 3. Set the environment variable 'heroku config:add HEARTBEAT_URL=http://yourapp.herokuapp.com'
+// 4. Restart the app 'heroku restart'
+//
+// @chamerling
+//
+
+var http = require('http')
+ , logger = require('util');
+
+exports.create = function(api, settings) {
+ if (settings.plugins && settings.plugins.heartbeat && settings.plugins.heartbeat.enable) {
+ logger.log('Creating the plugin: ' + __filename);
+
+ var url = process.env.HEARTBEAT_URL || 'http://' + (settings.hostname + ':' + (settings.port || '80')) + '/healthCheck';
+
+ setInterval(function() {
+ logger.log('[HEARTBEAT] ' + url);
+
+ http.get(url, function(response) {
+ logger.log('Got response from heartbeat');
+ }).on('error', function(e) {
+ logger.log('[HEARTBEAT] Error:' + e);
+ })
+ }, settings.plugins.heartbeat.period || 60000);
+ }
+};
View
@@ -152,6 +152,10 @@ exports.create = function() {
webhook: {
enable : false,
url: 'http://localhost:8080/api/webhook/test'
+ },
+ heartbeat: {
+ enable: false,
+ period: 20000
}
}
};

0 comments on commit 893130f

Please sign in to comment.