Merge pull request #24790 from overleaf/ls-use-script-runner

Update some scripts to use Script Runner

GitOrigin-RevId: aaa11f94dcfd328c158bb02d1b9fb2adfb1bb146
This commit is contained in:
Liangjun Song
2025-05-23 08:05:23 +00:00
committed by Copybot
parent d0010217cd
commit 2f87db9c0d
62 changed files with 225 additions and 112 deletions
@@ -1,7 +1,8 @@
import { db } from '../../app/src/infrastructure/mongodb.js'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
import { scriptRunner } from '../lib/ScriptRunner.mjs'
async function main() {
async function main(trackProgress) {
// update all applicable user models
await batchedUpdate(
db.users,
@@ -12,7 +13,10 @@ async function main() {
$set: {
'aiErrorAssistant.enabled': false,
},
}
},
undefined,
undefined,
{ trackProgress }
)
console.log('completed syncing writefull state with error assist')
}
@@ -20,7 +24,7 @@ async function main() {
export default main
try {
await main()
await scriptRunner(main)
process.exit(0)
} catch (error) {
console.error({ error })
@@ -3,6 +3,7 @@ import mongodb from 'mongodb-legacy'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { chunkArray } from '../helpers/chunkArray.mjs'
import { scriptRunner } from '../lib/ScriptRunner.mjs'
const { ObjectId } = mongodb
@@ -37,7 +38,7 @@ export default main
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await main()
await scriptRunner(main)
process.exit(0)
} catch (error) {
console.error({ error })
@@ -2,6 +2,7 @@ import { db } from '../../app/src/infrastructure/mongodb.js'
import mongodb from 'mongodb-legacy'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { scriptRunner } from '../lib/ScriptRunner.mjs'
const { ObjectId } = mongodb
@@ -36,7 +37,7 @@ export default main
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await main()
await scriptRunner(main)
process.exit(0)
} catch (error) {
console.error({ error })
@@ -4,10 +4,11 @@ import mongodb from 'mongodb-legacy'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { chunkArray } from '../helpers/chunkArray.mjs'
import { scriptRunner } from '../lib/ScriptRunner.mjs'
const { ObjectId } = mongodb
async function main() {
async function main(trackProgress) {
// search for file of users who already explicitly opted out first
const optOutPath = process.argv[2]
const optedOutFile = fs.readFileSync(optOutPath, 'utf8')
@@ -20,7 +21,10 @@ async function main() {
await batchedUpdate(
db.users,
{ 'writefull.enabled': false }, // and is false
{ $set: { 'writefull.enabled': null } }
{ $set: { 'writefull.enabled': null } },
undefined,
undefined,
{ trackProgress }
)
const chunks = chunkArray(optedOutList)
@@ -41,7 +45,7 @@ export default main
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await main()
await scriptRunner(main)
process.exit(0)
} catch (error) {
console.error({ error })