CartoDB-SQL-API/metro/metro.js
2021-04-05 16:03:33 +02:00

21 lines
691 B
JavaScript

'use strict';
const util = require('util');
const stream = require('stream');
const pipeline = util.promisify(stream.pipeline);
const split = require('split2');
const logCollector = require('./log-collector');
const MetricsCollector = require('./metrics-collector');
module.exports = async function metro ({ input = process.stdin, output = process.stdout, metrics = {} } = {}) {
const metricsCollector = new MetricsCollector(metrics);
const { stream: metricsStream } = metricsCollector;
try {
await metricsCollector.start();
await pipeline(input, split(), logCollector(), metricsStream, output);
} finally {
await metricsCollector.stop();
}
};