From fbac3c231b294e463055023669a584a106be73b3 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Tue, 29 Nov 2011 16:35:46 -0700 Subject: [PATCH] remove the deep __heartbeat__ checks performed from browserid (the webhead), while dbwriter should ping the database to ensure health - closes #566 --- bin/browserid | 8 +------- bin/dbwriter | 5 ++++- lib/db.js | 3 ++- lib/db/json.js | 4 ++++ lib/db/mysql.js | 6 ++++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/browserid b/bin/browserid index 80dd6e2a2..25a922658 100755 --- a/bin/browserid +++ b/bin/browserid @@ -79,13 +79,7 @@ if (!config.get('dbwriter_url')) { // #1 - Setup health check / heartbeat middleware. // This is in front of logging on purpose. see issue #537 -heartbeat.setup(app, function(cb) { - // let's check stuff! first the heartbeat of our keysigner - heartbeat.check(config.get('keysigner_url'), function(rv) { - if (!rv) return cb(rv); - heartbeat.check(config.get('dbwriter_url'), cb); - }); -}); +heartbeat.setup(app); // #2 - logging! all requests other than __heartbeat__ are logged app.use(express.logger({ diff --git a/bin/dbwriter b/bin/dbwriter index 9bd767bac..f4be27942 100755 --- a/bin/dbwriter +++ b/bin/dbwriter @@ -63,7 +63,10 @@ logger.info("dbwriter starting up"); // Setup health check / heartbeat middleware. // This is in front of logging on purpose. see issue #537 -heartbeat.setup(app); +heartbeat.setup(app, function(cb) { + // ping the database to verify we're really healthy. + db.ping(cb); +}); // logging! all requests other than __heartbeat__ are logged app.use(express.logger({ diff --git a/lib/db.js b/lib/db.js index 2b5cbbadc..e71702961 100644 --- a/lib/db.js +++ b/lib/db.js @@ -111,7 +111,8 @@ exports.onReady = function(f) { 'verificationSecretForEmail', 'checkAuth', 'listEmails', - 'lastStaged' + 'lastStaged', + 'ping' ].forEach(function(fn) { exports[fn] = function() { checkReady(); diff --git a/lib/db/json.js b/lib/db/json.js index f78045b00..dcbb213ec 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -358,3 +358,7 @@ exports.addTestUser = function(email, hash, cb) { cb(); }); }; + +exports.ping = function(cb) { + setTimeout(function() { cb(); }, 0); +}; diff --git a/lib/db/mysql.js b/lib/db/mysql.js index 574c5a72e..c1d417916 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -453,3 +453,9 @@ exports.addTestUser = function(email, hash, cb) { }); }); }; + +exports.ping = function() { + client.ping(function(err) { + cb(err); + }); +}; -- GitLab