1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-03-14 00:15:52 +01:00
unleash.unleash/lib/db/metrics-helper.js
Moritz Johner 3f7040772e feat: add db query latency metrics (#473)
* feat: add db metrics
Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>

* fix: use base unit

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
2019-08-04 11:10:50 +02:00

24 lines
629 B
JavaScript

'use strict';
const timer = require('../timer');
// wrapTimer keeps track of the timing of a async operation and emits
// a event on the given eventBus once the operation is complete
//
// the returned function is designed to be used as a .then(<func>) argument.
// It transparently passes the data to the following .then(<func>)
//
// usage: promise.then(wrapTimer(bus, type, { payload: 'ok' }))
const wrapTimer = (eventBus, event, args = {}) => {
const t = timer.new();
return data => {
args.time = t();
eventBus.emit(event, args);
return data;
};
};
module.exports = {
wrapTimer,
};