From d8a4209768066da1dc348a72204ad46e0e3970c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 5 Mar 2018 18:13:19 +0100 Subject: [PATCH] Middlewarify analysis-node-status endpoint --- lib/cartodb/controllers/layergroup.js | 29 +++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index a7c6ad2d..502ba16b 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -163,31 +163,26 @@ LayergroupController.prototype.register = function(app) { cors(), userMiddleware, this.prepareContext, - this.analysisNodeStatus.bind(this) + this.analysisNodeStatus(this.analysisStatusBackend) ); }; -LayergroupController.prototype.analysisNodeStatus = function(req, res, next) { - var self = this; - - step( - function retrieveNodeStatus() { - self.analysisStatusBackend.getNodeStatus(res.locals, this); - }, - function finish(err, nodeStatus, stats) { +LayergroupController.prototype.analysisNodeStatus = function (analysisStatusBackend) { + return function analysisNodeStatusMiddleware(req, res, next) { + analysisStatusBackend.getNodeStatus(res.locals, (err, nodeStatus, stats) => { req.profiler.add(stats || {}); if (err) { err.label = 'GET NODE STATUS'; - next(err); - } else { - self.sendResponse(req, res, nodeStatus, 200, { - 'Cache-Control': 'public,max-age=5', - 'Last-Modified': new Date().toUTCString() - }); + return next(err); } - } - ); + + this.sendResponse(req, res, nodeStatus, 200, { + 'Cache-Control': 'public,max-age=5', + 'Last-Modified': new Date().toUTCString() + }); + }); + }.bind(this); }; LayergroupController.prototype.getMapStoreMapConfigProvider = function (mapStore, userLimitsApi) {