From 2a6839f48cd3076a1c503a610ad4b1ec4f749867 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 27 Nov 2018 10:46:54 +0000 Subject: [PATCH] roll back async method for moment --- libraries/metrics/timeAsyncMethod.coffee | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/metrics/timeAsyncMethod.coffee b/libraries/metrics/timeAsyncMethod.coffee index 75eb9a131f..5248c43f79 100644 --- a/libraries/metrics/timeAsyncMethod.coffee +++ b/libraries/metrics/timeAsyncMethod.coffee @@ -5,15 +5,14 @@ module.exports = (obj, methodName, prefix, logger) -> if typeof obj[methodName] != 'function' throw new Error("[Metrics] expected object property '#{methodName}' to be a function") + key = "#{prefix}.#{methodName}" + realMethod = obj[methodName] - keys = prefix.split(".") - key = keys[0].toLowerCase() + startPrefix = prefix.split(".")[0] - - if keys[1]? - methodName = "#{keys[1]}_#{methodName}" - - console.log "Async method", keys, methodName + endPrefix = prefix.split(".")[1] + modifedMethodName = "#{endPrefix}_methodName" + console.log "Async method", prefix, key, methodName, modifedMethodName obj[methodName] = (originalArgs...) -> [firstArgs..., callback] = originalArgs @@ -23,8 +22,11 @@ module.exports = (obj, methodName, prefix, logger) -> logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback" return realMethod.apply this, originalArgs - console.log("creating timer for async method") - timer = new metrics.Timer(key, null, {method: methodName}) + console.log("creating timer for async method", prefix, startPrefix, modifedMethodName) + + + timer = new metrics.Timer(prefix, null, {method: methodName}) + console.log("changed timer for async method", prefix, methodName, key) realMethod.call this, firstArgs..., (callbackArgs...) -> elapsedTime = timer.done()