fix(api): дождаться фоновых записей перед операцией с БД
This commit is contained in:
1 parent
8682f2a7a5
commit
2943032462
18 files changed
+183
-29
No files matched your search
@@ -9,6 +9,7 @@ import { pool } from "../db/index.js"
|
||||
import { withOperationLock } from "../db/operation-lock.js"
|
||||
import { executeDatabaseOperation, type DatabaseOperationWarnings } from "./system-database-operation.js"
|
||||
import { restartSchedulerAfterDatabaseOperation, stopSchedulerForDatabaseOperation } from "./scheduler.js"
|
||||
import { pauseRipeBackgroundWork, resumeRipeBackgroundWork } from "./traffic-flow-ripe.js"
|
||||
import {
|
||||
restartTrafficFlowListenerAfterDatabaseOperation,
|
||||
stopTrafficFlowListenerForDatabaseOperation,
|
||||
@@ -49,9 +50,15 @@ function spawnCollected(command: string, args: string[], opts?: { stdin?: Buffer
|
||||
async function withDatabaseOperation<T extends object>(fn: () => Promise<T>): Promise<T & DatabaseOperationWarnings> {
|
||||
return withOperationLock(() => pool.connect(), BACKUP_LOCK_KEY, () => executeDatabaseOperation(fn, {
|
||||
stopListener: stopTrafficFlowListenerForDatabaseOperation,
|
||||
stopScheduler: stopSchedulerForDatabaseOperation,
|
||||
stopScheduler: async () => {
|
||||
await stopSchedulerForDatabaseOperation()
|
||||
await pauseRipeBackgroundWork()
|
||||
},
|
||||
startListener: restartTrafficFlowListenerAfterDatabaseOperation,
|
||||
startScheduler: restartSchedulerAfterDatabaseOperation,
|
||||
startScheduler: async () => {
|
||||
resumeRipeBackgroundWork()
|
||||
await restartSchedulerAfterDatabaseOperation()
|
||||
},
|
||||
}), "Операция с базой приложения уже выполняется")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user