Merge pull request #9099 from overleaf/jpa-web-graceful-shutdown

[web] introduce graceful shutdown

GitOrigin-RevId: f42793a96f1e0304c57a855241bffa32bb291864
This commit is contained in:
Jakob Ackermann
2022-08-05 08:03:27 +00:00
committed by Copybot
parent ab4a01f15b
commit e5e6be99f8
16 changed files with 273 additions and 35 deletions
@@ -10,9 +10,14 @@ const FileTypeManager = require('../Uploads/FileTypeManager')
const CooldownManager = require('../Cooldown/CooldownManager')
const Errors = require('../Errors/Errors')
const Modules = require('../../infrastructure/Modules')
const {
BackgroundTaskTracker,
} = require('../../infrastructure/GracefulShutdown')
const ROOT_DOC_TIMEOUT_LENGTH = 30 * 1000
const rootDocResets = new BackgroundTaskTracker('root doc resets')
function newUpdate(userId, projectName, path, updateRequest, source, callback) {
getOrCreateProject(userId, projectName, (err, project) => {
if (err) {
@@ -113,8 +118,11 @@ function getOrCreateProject(userId, projectName, callback) {
// have a crack at setting the root doc after a while, on creation
// we won't have it yet, but should have been sent it it within 30
// seconds
rootDocResets.add()
setTimeout(() => {
ProjectRootDocManager.setRootDocAutomatically(project._id)
ProjectRootDocManager.setRootDocAutomatically(project._id, () => {
rootDocResets.done()
})
}, ROOT_DOC_TIMEOUT_LENGTH)
callback(err, project)
}