mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] migrate the app to the native mongo driver
acceptance tests to follow in a separate commit
This commit is contained in:
parent
cc04120dbc
commit
f80a92ce46
5 changed files with 65 additions and 20 deletions
|
@ -17,14 +17,14 @@ const DispatchManager = require('./app/js/DispatchManager')
|
|||
const DeleteQueueManager = require('./app/js/DeleteQueueManager')
|
||||
const Errors = require('./app/js/Errors')
|
||||
const HttpController = require('./app/js/HttpController')
|
||||
const mongojs = require('./app/js/mongojs')
|
||||
const mongodb = require('./app/js/mongodb')
|
||||
const async = require('async')
|
||||
|
||||
const Path = require('path')
|
||||
const bodyParser = require('body-parser')
|
||||
|
||||
Metrics.mongodb.monitor(
|
||||
Path.resolve(__dirname, '/node_modules/mongojs/node_modules/mongodb'),
|
||||
Path.resolve(__dirname, '/node_modules/mongodb'),
|
||||
logger
|
||||
)
|
||||
Metrics.event_loop.monitor(logger, 100)
|
||||
|
@ -158,7 +158,7 @@ app.get('/health_check', (req, res, next) => {
|
|||
})
|
||||
},
|
||||
(cb) => {
|
||||
mongojs.healthCheck((error) => {
|
||||
mongodb.healthCheck((error) => {
|
||||
if (error) {
|
||||
logger.err({ err: error }, 'failed mongo health check')
|
||||
}
|
||||
|
@ -219,13 +219,27 @@ const host = Settings.internal.documentupdater.host || 'localhost'
|
|||
|
||||
if (!module.parent) {
|
||||
// Called directly
|
||||
app.listen(port, host, () => {
|
||||
logger.info(`Document-updater starting up, listening on ${host}:${port}`)
|
||||
mongodb
|
||||
.waitForDb()
|
||||
.then(() => {
|
||||
app.listen(port, host, function (err) {
|
||||
if (err) {
|
||||
logger.fatal({ err }, `Cannot bind to ${host}:${port}. Exiting.`)
|
||||
process.exit(1)
|
||||
}
|
||||
logger.info(
|
||||
`Document-updater starting up, listening on ${host}:${port}`
|
||||
)
|
||||
if (Settings.continuousBackgroundFlush) {
|
||||
logger.info('Starting continuous background flush')
|
||||
DeleteQueueManager.startBackgroundFlush()
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = app
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let SnapshotManager
|
||||
const { db, ObjectId } = require('./mongojs')
|
||||
const { db, ObjectId } = require('./mongodb')
|
||||
|
||||
module.exports = SnapshotManager = {
|
||||
recordSnapshot(
|
||||
|
@ -30,7 +30,7 @@ module.exports = SnapshotManager = {
|
|||
} catch (error) {
|
||||
return callback(error)
|
||||
}
|
||||
return db.docSnapshots.insert(
|
||||
db.docSnapshots.insertOne(
|
||||
{
|
||||
project_id,
|
||||
doc_id,
|
||||
|
|
30
services/document-updater/app/js/mongodb.js
Normal file
30
services/document-updater/app/js/mongodb.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
const clientPromise = MongoClient.connect(Settings.mongo.url)
|
||||
|
||||
async function healthCheck() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
const res = await internalDb.command({ ping: 1 })
|
||||
if (!res.ok) {
|
||||
throw new Error('failed mongo ping')
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForDb() {
|
||||
await clientPromise
|
||||
}
|
||||
|
||||
const db = {}
|
||||
waitForDb().then(async function () {
|
||||
const internalDb = (await clientPromise).db()
|
||||
|
||||
db.docSnapshots = internalDb.collection('docSnapshots')
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
ObjectId,
|
||||
healthCheck: require('util').callbackify(healthCheck),
|
||||
waitForDb
|
||||
}
|
16
services/document-updater/package-lock.json
generated
16
services/document-updater/package-lock.json
generated
|
@ -1480,9 +1480,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"bson": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz",
|
||||
"integrity": "sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg=="
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.5.tgz",
|
||||
"integrity": "sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg=="
|
||||
},
|
||||
"buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
|
@ -4409,12 +4409,12 @@
|
|||
"optional": true
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "3.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.5.tgz",
|
||||
"integrity": "sha512-GCjDxR3UOltDq00Zcpzql6dQo1sVry60OXJY3TDmFc2SWFY6c8Gn1Ardidc5jDirvJrx2GC3knGOImKphbSL3A==",
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.0.tgz",
|
||||
"integrity": "sha512-/XWWub1mHZVoqEsUppE0GV7u9kanLvHxho6EvBxQbShXTKYF9trhZC2NzbulRGeG7xMJHD8IOWRcdKx5LPjAjQ==",
|
||||
"requires": {
|
||||
"bl": "^2.2.0",
|
||||
"bson": "^1.1.1",
|
||||
"bson": "^1.1.4",
|
||||
"denque": "^1.4.1",
|
||||
"require_optional": "^1.0.1",
|
||||
"safe-buffer": "^5.1.2",
|
||||
|
@ -5939,7 +5939,7 @@
|
|||
"require_optional": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
|
||||
"integrity": "sha1-TPNaQkf2TKPfjC7yCMxJSxyo/C4=",
|
||||
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
|
||||
"requires": {
|
||||
"resolve-from": "^2.0.0",
|
||||
"semver": "^5.1.0"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"lodash": "^4.17.13",
|
||||
"logger-sharelatex": "^2.2.0",
|
||||
"metrics-sharelatex": "^2.6.2",
|
||||
"mongodb": "^3.6.0",
|
||||
"mongojs": "^3.1.0",
|
||||
"redis-sharelatex": "^1.0.13",
|
||||
"request": "^2.88.2",
|
||||
|
|
Loading…
Reference in a new issue