mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 20:13:46 -05:00
4b308553be
[misc] move the linting setup to the root of the monorepo GitOrigin-RevId: 1633e2a58598add0b727738cd3bfba0ab7bae781
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
module.exports = {
|
|
monitor(logger, interval, logThreshold) {
|
|
if (interval == null) {
|
|
interval = 1000
|
|
}
|
|
if (logThreshold == null) {
|
|
logThreshold = 100
|
|
}
|
|
const Metrics = require('./index')
|
|
// check for logger on startup to avoid exceptions later if undefined
|
|
if (logger == null) {
|
|
throw new Error('logger is undefined')
|
|
}
|
|
// monitor delay in setInterval to detect event loop blocking
|
|
let previous = Date.now()
|
|
const intervalId = setInterval(function () {
|
|
const now = Date.now()
|
|
const offset = now - previous - interval
|
|
if (offset > logThreshold) {
|
|
logger.warn({ offset }, 'slow event loop')
|
|
}
|
|
previous = now
|
|
return Metrics.timing('event-loop-millsec', offset)
|
|
}, interval)
|
|
|
|
return Metrics.registerDestructor(() => clearInterval(intervalId))
|
|
},
|
|
}
|