added sync mutex for consistency checks and backup

This commit is contained in:
azivner
2018-01-04 21:37:36 -05:00
parent a6a687c4a6
commit 663bd1a8fe
7 changed files with 61 additions and 40 deletions

View File

@@ -14,22 +14,13 @@ const fs = require('fs');
const app_info = require('./app_info');
const messaging = require('./messaging');
const sync_setup = require('./sync_setup');
const sync_mutex = require('./sync_mutex');
let syncInProgress = false;
let proxyToggle = true;
let syncServerCertificate = null;
async function sync() {
if (syncInProgress) {
log.info("Sync already in progress");
return {
success: false,
message: "Sync already in progress"
};
}
syncInProgress = true;
const releaseMutex = await sync_mutex.acquire();
try {
if (!await sql.isDbUpToDate()) {
@@ -74,7 +65,7 @@ async function sync() {
}
}
finally {
syncInProgress = false;
releaseMutex();
}
}