[project-history] migrate simple request usages to fetch-utils (#32539)

* [project-history] remove unused getQueueCounts in tests

* [project-history] migrate simple request usages to fetch-utils

GitOrigin-RevId: 0e299a9d2ea968b87d7f0f2fc1626393ca4e4fdc
This commit is contained in:
Jakob Ackermann
2026-04-01 08:05:41 +00:00
committed by Copybot
parent 7a4ee32af3
commit ad508b1882
6 changed files with 79 additions and 118 deletions
@@ -1,82 +1,50 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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
*/
import { ObjectId } from './mongodb.js'
import request from 'request'
import async from 'async'
import settings from '@overleaf/settings'
import logger from '@overleaf/logger'
import OError from '@overleaf/o-error'
import * as LockManager from './LockManager.js'
import { fetchNothing } from '@overleaf/fetch-utils'
import { callbackify } from '@overleaf/promise-utils'
const { port } = settings.internal.history
export function check(callback) {
const checkCb = callbackify(check)
export { checkCb as check }
async function check() {
const projectId = new ObjectId(settings.history.healthCheck.project_id)
const url = `http://127.0.0.1:${port}/project/${projectId}`
logger.debug({ projectId }, 'running health check')
const jobs = [
cb =>
request.get(
{ url: `http://127.0.0.1:${port}/check_lock`, timeout: 3000 },
function (err, res, body) {
if (err != null) {
OError.tag(err, 'error checking lock for health check', {
project_id: projectId,
})
return cb(err)
} else if ((res != null ? res.statusCode : undefined) !== 200) {
return cb(
new OError('status code not 200', { statusCode: res.statusCode })
)
} else {
return cb()
}
}
),
cb =>
request.post(
{ url: `${url}/flush`, timeout: 10000 },
function (err, res, body) {
if (err != null) {
OError.tag(err, 'error flushing for health check', {
project_id: projectId,
})
return cb(err)
} else if ((res != null ? res.statusCode : undefined) !== 204) {
return cb(
new OError('status code not 204', { statusCode: res.statusCode })
)
} else {
return cb()
}
}
),
cb =>
request.get(
{ url: `${url}/updates`, timeout: 10000 },
function (err, res, body) {
if (err != null) {
OError.tag(err, 'error getting updates for health check', {
project_id: projectId,
})
return cb(err)
} else if ((res != null ? res.statusCode : undefined) !== 200) {
return cb(
new OError('status code not 200', { statusCode: res.statusCode })
)
} else {
return cb()
}
}
),
]
return async.series(jobs, callback)
try {
await fetchNothing(`http://127.0.0.1:${port}/check_lock`, {
signal: AbortSignal.timeout(3_000),
})
} catch (err) {
throw OError.tag(err, 'error checking lock for health check', {
project_id: projectId,
})
}
try {
await fetchNothing(`${url}/flush`, {
method: 'POST',
signal: AbortSignal.timeout(10_000),
})
} catch (err) {
throw OError.tag(err, 'error flushing for health check', {
project_id: projectId,
})
}
try {
await fetchNothing(`${url}/updates`, {
signal: AbortSignal.timeout(10_000),
})
} catch (err) {
throw OError.tag(err, 'error getting updates for health check', {
project_id: projectId,
})
}
}
export function checkLock(callback) {
@@ -1,6 +1,5 @@
import logger from '@overleaf/logger'
import OError from '@overleaf/o-error'
import request from 'request'
import * as UpdatesProcessor from './UpdatesProcessor.js'
import * as SummarizedUpdatesManager from './SummarizedUpdatesManager.js'
import * as DiffManager from './DiffManager.js'
@@ -16,7 +15,7 @@ import * as HistoryApiManager from './HistoryApiManager.js'
import * as RetryManager from './RetryManager.js'
import * as FlushManager from './FlushManager.js'
import { pipeline } from 'node:stream'
import { RequestFailedError } from '@overleaf/fetch-utils'
import { fetchNothing, RequestFailedError } from '@overleaf/fetch-utils'
import { z, zz, parseReq } from '@overleaf/validation-tools'
const ONE_DAY_IN_SECONDS = 24 * 60 * 60
@@ -800,7 +799,9 @@ export function retryFailures(req, res, next) {
const found = key.match(/^X-CALLBACK-(.*)/i)
callbackHeaders[found[1]] = req.headers[key]
}
request({ url: callbackUrl, headers: callbackHeaders })
fetchNothing(callbackUrl, { headers: callbackHeaders }).catch(err => {
logger.warn({ err }, 'failed to ping callback url')
})
}
} else {
if (error != null) {