Merge pull request #98 from overleaf/jpa-hotfix-pack-worker

[PackWorker] fixes for the native mongo driver
This commit is contained in:
Jakob Ackermann 2020-09-29 15:17:39 +02:00 committed by GitHub
commit 3da2e0370a
2 changed files with 30 additions and 6 deletions

View file

@ -15,10 +15,11 @@
*/
let LIMIT, pending
let project_id, doc_id
const { callbackify } = require('util')
const Settings = require('settings-sharelatex')
const async = require('async')
const _ = require('underscore')
const { db, ObjectId } = require('./mongodb')
const { db, ObjectId, waitForDb, closeDb } = require('./mongodb')
const fs = require('fs')
const Metrics = require('metrics-sharelatex')
Metrics.initialize('track-changes')
@ -84,7 +85,7 @@ const finish = function () {
clearTimeout(shutDownTimer)
}
logger.log('closing db')
return db.close(function () {
callbackify(closeDb)(function () {
logger.log('closing LockManager Redis Connection')
return LockManager.close(function () {
logger.log(
@ -160,10 +161,21 @@ const ObjectIdFromDate = function (date) {
// find packs to be marked as finalised:true, those which have a newer pack present
// then only consider finalised:true packs for archiving
waitForDb()
.then(() => {
if (pending != null) {
logger.log(`got ${pending.length} entries from ${source}`)
processUpdates(pending)
} else {
processFromOneWeekAgo()
}
})
.catch((err) => {
logger.fatal({ err }, 'cannot connect to mongo, exiting')
process.exit(1)
})
function processFromOneWeekAgo() {
const oneWeekAgo = new Date(Date.now() - 7 * DAYS)
db.docHistory
.find(

View file

@ -23,8 +23,20 @@ async function setupDb() {
db.projectHistoryMetaData = internalDb.collection('projectHistoryMetaData')
}
async function closeDb() {
let client
try {
client = await clientPromise
} catch (e) {
// there is nothing to close
return
}
return client.close()
}
module.exports = {
db,
ObjectId,
closeDb,
waitForDb
}