mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 14:14:04 +00:00
f7275a6c4b
Upgrade logger and metrics in all services GitOrigin-RevId: 2baf63eeeab77fb3559cf763ddacfbf4b745cd0b
34 lines
746 B
JavaScript
34 lines
746 B
JavaScript
const logger = require('@overleaf/logger')
|
|
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
|
|
}
|
|
}
|
|
}
|