Merge pull request #3255 from overleaf/jpa-fix-scripts

[misc] add waitForDb wrapper to scripts with indirect mongo access

GitOrigin-RevId: 009331f91a45f075a35b0b6e90c4352e55908c21
This commit is contained in:
Jakob Ackermann 2020-10-05 10:29:37 +02:00 committed by Copybot
parent b3197b5f12
commit ad52f7dc01
5 changed files with 65 additions and 31 deletions

View file

@ -1,17 +1,27 @@
const { waitForDb } = require('../app/src/infrastructure/mongodb')
const InstitutionsManager = require('../app/src/Features/Institutions/InstitutionsManager')
const institutionId = parseInt(process.argv[2])
if (isNaN(institutionId)) throw new Error('No institution id')
console.log('Checking users of institution', institutionId)
InstitutionsManager.checkInstitutionUsers(institutionId, function(
error,
usersSummary
) {
if (error) {
console.log(error)
} else {
console.log(usersSummary)
}
process.exit()
})
waitForDb()
.then(main)
.catch(err => {
console.error(err)
process.exit(1)
})
function main() {
InstitutionsManager.checkInstitutionUsers(institutionId, function(
error,
usersSummary
) {
if (error) {
console.log(error)
} else {
console.log(usersSummary)
}
process.exit()
})
}

View file

@ -1,3 +1,4 @@
const { waitForDb } = require('../app/src/infrastructure/mongodb')
const ProjectDetailsHandler = require('../app/src/Features/Project/ProjectDetailsHandler')
const projectId = process.argv[2]
@ -6,14 +7,23 @@ if (!/^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/.test(projectId)) {
process.exit(1)
}
ProjectDetailsHandler.clearTokens(projectId, err => {
if (err) {
console.error(
`Error clearing project tokens from project ${projectId}`,
err
)
waitForDb()
.then(main)
.catch(err => {
console.error(err)
process.exit(1)
}
console.log(`Successfully cleared project tokens from project ${projectId}`)
process.exit(0)
})
})
function main() {
ProjectDetailsHandler.clearTokens(projectId, err => {
if (err) {
console.error(
`Error clearing project tokens from project ${projectId}`,
err
)
process.exit(1)
}
console.log(`Successfully cleared project tokens from project ${projectId}`)
process.exit(0)
})
}

View file

@ -1,4 +1,5 @@
const readline = require('readline')
const { waitForDb } = require('../app/src/infrastructure/mongodb')
const ProjectEntityHandler = require('../app/src/Features/Project/ProjectEntityHandler')
const ProjectGetter = require('../app/src/Features/Project/ProjectGetter')
const Errors = require('../app/src/Features/Errors/Errors')
@ -37,7 +38,8 @@ async function countFiles() {
}
}
countFiles()
waitForDb()
.then(countFiles)
.then(() => {
process.exit(0)
})

View file

@ -1,3 +1,4 @@
const { waitForDb } = require('../app/src/infrastructure/mongodb')
const { User } = require('../app/src/models/User')
const UserController = require('../app/src/Features/User/UserController')
require('logger-sharelatex').logger.level('error')
@ -41,7 +42,8 @@ async function run() {
}
}
run()
waitForDb()
.then(run)
.then(() => {
process.exit()
})

View file

@ -1,14 +1,24 @@
const { waitForDb } = require('../app/src/infrastructure/mongodb')
const InstitutionsManager = require('../app/src/Features/Institutions/InstitutionsManager')
const institutionId = parseInt(process.argv[2])
if (isNaN(institutionId)) throw new Error('No institution id')
console.log('Upgrading users of institution', institutionId)
InstitutionsManager.upgradeInstitutionUsers(institutionId, function(error) {
if (error) {
console.log(error)
} else {
console.log('DONE 👌')
}
process.exit()
})
waitForDb()
.then(main)
.catch(err => {
console.error(err)
process.exit(1)
})
function main() {
InstitutionsManager.upgradeInstitutionUsers(institutionId, function(error) {
if (error) {
console.log(error)
} else {
console.log('DONE 👌')
}
process.exit()
})
}