From 4825a1f557f984f9f9049fa98500dbce3f4ce4e9 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 1 Jun 2016 14:57:06 +0100 Subject: [PATCH] extract clearup func so it always runs --- .../notifications/app/coffee/HealthCheckController.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/notifications/app/coffee/HealthCheckController.coffee b/services/notifications/app/coffee/HealthCheckController.coffee index 52db88518a..1adb0433d4 100644 --- a/services/notifications/app/coffee/HealthCheckController.coffee +++ b/services/notifications/app/coffee/HealthCheckController.coffee @@ -13,6 +13,9 @@ db = mongojs(Settings.mongo?.url, ['notifications']) module.exports = check : (callback)-> user_id = ObjectId() + cleanupNotifications = (callback)-> + db.notifications.remove {user_id:user_id}, callback + notification_key = "smoke-test-notification-#{ObjectId()}" getOpts = (endPath)-> {url:"http://localhost:#{port}/user/#{user_id}#{endPath}", timeout:5000} logger.log user_id:user_id, opts:getOpts(), key:notification_key, user_id:user_id, "Health Check: running" @@ -43,7 +46,8 @@ module.exports = async.series jobs, (err, body)-> if err? logger.err err:err, "Health Check: error running health check" - return callback(err) + cleanupNotifications -> + return callback(err) else notification_id = body[1][0]._id notification_key = body[1][0].key @@ -59,4 +63,4 @@ module.exports = if err? logger.err err, opts, "Health Check: error cleaning up notification" return callback(err) - db.notifications.remove {user_id:user_id}, callback + cleanupNotifications callback