Просмотр исходного кода

Merge pull request #22019 from overleaf/jpa-cleanup

[history-v1] back_fill_file_hash: cleanup BUFFER_DIR when done

GitOrigin-RevId: 6413292bbe8cca470919b740d7e2b45fc5e7d824
Jakob Ackermann 1 год назад
Родитель
Сommit
44e0428496

+ 7 - 0
services/history-v1/storage/scripts/back_fill_file_hash.mjs

@@ -1101,6 +1101,13 @@ try {
     await main()
   } finally {
     printStats()
+    try {
+      // Perform non-recursive removal of the BUFFER_DIR. Individual files
+      // should get removed in parallel as part of batch processing.
+      await fs.promises.rmdir(BUFFER_DIR)
+    } catch (err) {
+      console.error(`cleanup of BUFFER_DIR=${BUFFER_DIR} failed`, err)
+    }
   }
 
   let code = 0

+ 4 - 0
services/history-v1/test/acceptance/js/storage/back_fill_file_hash.test.mjs

@@ -1,3 +1,4 @@
+import fs from 'node:fs'
 import Crypto from 'node:crypto'
 import Stream from 'node:stream'
 import { setTimeout } from 'node:timers/promises'
@@ -511,6 +512,9 @@ describe('back_fill_file_hash script', function () {
       }
       result = { stdout, stderr, status: code }
     }
+    expect((await fs.promises.readdir('/tmp')).join(';')).to.not.match(
+      /back_fill_file_hash/
+    )
     const extraStatsKeys = [
       'eventLoop',
       'readFromGCSThroughputMiBPerSecond',