Kaynağa Gözat

Merge pull request #33023 from overleaf/copilot/add-warning-for-unprocessed-projects

Clarify clear_deleted.js completion output for force mode and partial processing

GitOrigin-RevId: 11d9595e5b43bb8df8e1c7f664f4c08c3fbd4509
Brian Gough 5 ay önce
ebeveyn
işleme
e6861ab6fa

+ 20 - 2
services/project-history/scripts/clear_deleted.js

@@ -4,6 +4,7 @@ import async from 'async'
 import logger from '@overleaf/logger'
 import logger from '@overleaf/logger'
 import Settings from '@overleaf/settings'
 import Settings from '@overleaf/settings'
 import redis from '@overleaf/redis-wrapper'
 import redis from '@overleaf/redis-wrapper'
+import path from 'node:path'
 import { db, ObjectId } from '../app/js/mongodb.js'
 import { db, ObjectId } from '../app/js/mongodb.js'
 
 
 logger.logger.level('fatal')
 logger.logger.level('fatal')
@@ -118,7 +119,7 @@ main().catch(error => {
 })
 })
 
 
 function processFailures(results) {
 function processFailures(results) {
-  if (argv.length === 0) {
+  if (limit === null) {
     console.log(`
     console.log(`
 Usage: node clear_deleted.js [QUEUES] [FORCE]
 Usage: node clear_deleted.js [QUEUES] [FORCE]
 
 
@@ -126,11 +127,28 @@ where
     QUEUES is the number of queues to process
     QUEUES is the number of queues to process
     FORCE is the string "force" when we're ready to delete the queues. Without it, this script does a dry-run
     FORCE is the string "force" when we're ready to delete the queues. Without it, this script does a dry-run
 `)
 `)
+    process.exit(0)
   }
   }
   console.log('number of stuck projects', results.length)
   console.log('number of stuck projects', results.length)
+  console.log('force mode', force ? 'enabled' : 'disabled (dry run)')
+  const projectsToProcess = results.slice(0, limit)
+  const unprocessedProjects = results.length - projectsToProcess.length
+  const scriptFileName = path.basename(process.argv[1])
+  const limitOrPlaceholder = limit ?? 100
+  const forceExampleCommand = `node scripts/${scriptFileName} ${limitOrPlaceholder} force`
   // now check if the project is truly deleted in mongo
   // now check if the project is truly deleted in mongo
-  async.eachSeries(results.slice(0, limit), checkAndClear, err => {
+  async.eachSeries(projectsToProcess, checkAndClear, err => {
     console.log('DONE', err)
     console.log('DONE', err)
+    if (unprocessedProjects > 0) {
+      console.warn(
+        `WARNING: ${unprocessedProjects} project(s) were not processed in this run`
+      )
+    }
+    if (!force) {
+      console.warn(
+        `Dry run only. Rerun with force to apply changes, for example: ${forceExampleCommand}`
+      )
+    }
     process.exit()
     process.exit()
   })
   })
 }
 }