overleaf/services/filestore/app/js/ImageOptimiser.js
Jakob Ackermann 95f3bcef21 [misc] bump metrics module to 3.4.1
- renamed package from `metrics-sharelatex` to `@overleaf/metrics`
- drop support for statsd backend
- decaffeinate
- compress `/metrics` response using gzip
- bump debugging agents to latest versions
- expose prometheus interfaces for custom metrics (custom tags)
- cleanup of open sockets metrics
- fix deprecation warnings for header access
2020-11-25 11:57:23 +00:00

34 lines
744 B
JavaScript

const logger = require('logger-sharelatex')
const metrics = require('@overleaf/metrics')
const { callbackify } = require('util')
const safeExec = require('./SafeExec').promises
module.exports = {
compressPng: callbackify(compressPng),
promises: {
compressPng
}
}
async function compressPng(localPath, callback) {
const timer = new metrics.Timer('compressPng')
const args = ['optipng', localPath]
const opts = {
timeout: 30 * 1000,
killSignal: 'SIGKILL'
}
try {
await safeExec(args, opts)
timer.done()
} catch (err) {
if (err.code === 'SIGKILL') {
logger.warn(
{ err, stderr: err.stderr, localPath },
'optimiser timeout reached'
)
} else {
throw err
}
}
}