2020-02-17 12:34:21 -05:00
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:34:04 -05:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2020-09-10 07:58:06 -04:00
|
|
|
const { ObjectId } = require('./mongodb')
|
2020-02-17 12:34:28 -05:00
|
|
|
const request = require('request')
|
|
|
|
const async = require('async')
|
2021-07-12 12:47:16 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2020-02-17 12:34:28 -05:00
|
|
|
const { port } = settings.internal.trackchanges
|
2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-02-17 12:34:28 -05:00
|
|
|
const LockManager = require('./LockManager')
|
2015-10-19 05:59:39 -04:00
|
|
|
|
2020-02-17 12:34:04 -05:00
|
|
|
module.exports = {
|
2020-02-17 12:34:28 -05:00
|
|
|
check(callback) {
|
2023-03-21 08:21:51 -04:00
|
|
|
const projectId = ObjectId(settings.trackchanges.healthCheck.project_id)
|
|
|
|
const url = `http://localhost:${port}/project/${projectId}`
|
|
|
|
logger.debug({ projectId }, 'running health check')
|
2020-02-17 12:34:28 -05:00
|
|
|
const jobs = [
|
2021-07-13 07:04:43 -04:00
|
|
|
cb =>
|
2020-02-17 12:34:28 -05:00
|
|
|
request.get(
|
|
|
|
{ url: `http://localhost:${port}/check_lock`, timeout: 3000 },
|
2020-06-04 04:24:21 -04:00
|
|
|
function (err, res, body) {
|
2020-02-17 12:34:28 -05:00
|
|
|
if (err != null) {
|
|
|
|
logger.err(
|
2023-03-21 08:21:51 -04:00
|
|
|
{ err, projectId },
|
2020-02-17 12:34:28 -05:00
|
|
|
'error checking lock for health check'
|
|
|
|
)
|
|
|
|
return cb(err)
|
|
|
|
} else if ((res != null ? res.statusCode : undefined) !== 200) {
|
2021-10-27 05:49:42 -04:00
|
|
|
return cb(
|
|
|
|
new Error(`status code not 200, it's ${res.statusCode}`)
|
|
|
|
)
|
2020-02-17 12:34:28 -05:00
|
|
|
} else {
|
|
|
|
return cb()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
2021-07-13 07:04:43 -04:00
|
|
|
cb =>
|
|
|
|
request.post(
|
|
|
|
{ url: `${url}/flush`, timeout: 10000 },
|
|
|
|
function (err, res, body) {
|
|
|
|
if (err != null) {
|
2023-03-21 08:21:51 -04:00
|
|
|
logger.err({ err, projectId }, 'error flushing for health check')
|
2021-07-13 07:04:43 -04:00
|
|
|
return cb(err)
|
|
|
|
} else if ((res != null ? res.statusCode : undefined) !== 204) {
|
2021-10-27 05:49:42 -04:00
|
|
|
return cb(
|
|
|
|
new Error(`status code not 204, it's ${res.statusCode}`)
|
|
|
|
)
|
2021-07-13 07:04:43 -04:00
|
|
|
} else {
|
|
|
|
return cb()
|
|
|
|
}
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
),
|
|
|
|
cb =>
|
|
|
|
request.get(
|
|
|
|
{ url: `${url}/updates`, timeout: 10000 },
|
|
|
|
function (err, res, body) {
|
|
|
|
if (err != null) {
|
|
|
|
logger.err(
|
2023-03-21 08:21:51 -04:00
|
|
|
{ err, projectId },
|
2021-07-13 07:04:43 -04:00
|
|
|
'error getting updates for health check'
|
|
|
|
)
|
|
|
|
return cb(err)
|
|
|
|
} else if ((res != null ? res.statusCode : undefined) !== 200) {
|
2021-10-27 05:49:42 -04:00
|
|
|
return cb(
|
|
|
|
new Error(`status code not 200, it's ${res.statusCode}`)
|
|
|
|
)
|
2021-07-13 07:04:43 -04:00
|
|
|
} else {
|
|
|
|
return cb()
|
|
|
|
}
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
2021-07-13 07:04:43 -04:00
|
|
|
),
|
2020-02-17 12:34:28 -05:00
|
|
|
]
|
|
|
|
return async.series(jobs, callback)
|
|
|
|
},
|
2016-01-27 11:04:55 -05:00
|
|
|
|
2020-02-17 12:34:28 -05:00
|
|
|
checkLock(callback) {
|
|
|
|
return LockManager.healthCheck(callback)
|
2021-07-13 07:04:43 -04:00
|
|
|
},
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|