mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-06 04:50:03 -06:00
reddit plugin configuration from file, not from options now. Scheduling, refactoring of sync mutex
This commit is contained in:
@@ -23,9 +23,8 @@ async function regularBackup() {
|
||||
|
||||
async function backupNow() {
|
||||
// we don't want to backup DB in the middle of sync with potentially inconsistent DB state
|
||||
const releaseMutex = await sync_mutex.acquire();
|
||||
|
||||
try {
|
||||
await sync_mutex.doExclusively(async () => {
|
||||
const now = utils.nowDate();
|
||||
|
||||
const backupFile = dataDir.BACKUP_DIR + "/" + "backup-" + utils.getDateTimeForFile() + ".db";
|
||||
@@ -37,10 +36,7 @@ async function backupNow() {
|
||||
await sql.doInTransaction(async () => {
|
||||
await options.setOption('last_backup_date', now);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
releaseMutex();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function cleanupOldBackups() {
|
||||
|
||||
@@ -217,18 +217,14 @@ async function runAllChecks() {
|
||||
async function runChecks() {
|
||||
let errorList;
|
||||
let elapsedTimeMs;
|
||||
const releaseMutex = await sync_mutex.acquire();
|
||||
|
||||
try {
|
||||
await sync_mutex.doExclusively(async () => {
|
||||
const startTime = new Date();
|
||||
|
||||
errorList = await runAllChecks();
|
||||
|
||||
elapsedTimeMs = new Date().getTime() - startTime.getTime();
|
||||
}
|
||||
finally {
|
||||
releaseMutex();
|
||||
}
|
||||
});
|
||||
|
||||
if (errorList.length > 0) {
|
||||
log.info(`Consistency checks failed (took ${elapsedTimeMs}ms) with these errors: ` + JSON.stringify(errorList));
|
||||
|
||||
@@ -20,25 +20,25 @@ let proxyToggle = true;
|
||||
let syncServerCertificate = null;
|
||||
|
||||
async function sync() {
|
||||
const releaseMutex = await sync_mutex.acquire();
|
||||
|
||||
try {
|
||||
if (!await sql.isDbUpToDate()) {
|
||||
return {
|
||||
success: false,
|
||||
message: "DB not up to date"
|
||||
};
|
||||
}
|
||||
await sync_mutex.doExclusively(async () => {
|
||||
if (!await sql.isDbUpToDate()) {
|
||||
return {
|
||||
success: false,
|
||||
message: "DB not up to date"
|
||||
};
|
||||
}
|
||||
|
||||
const syncContext = await login();
|
||||
const syncContext = await login();
|
||||
|
||||
await pushSync(syncContext);
|
||||
await pushSync(syncContext);
|
||||
|
||||
await pullSync(syncContext);
|
||||
await pullSync(syncContext);
|
||||
|
||||
await pushSync(syncContext);
|
||||
await pushSync(syncContext);
|
||||
|
||||
await checkContentHash(syncContext);
|
||||
await checkContentHash(syncContext);
|
||||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
@@ -64,9 +64,6 @@ async function sync() {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
releaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
async function login() {
|
||||
|
||||
@@ -4,5 +4,20 @@
|
||||
*/
|
||||
|
||||
const Mutex = require('async-mutex').Mutex;
|
||||
const instance = new Mutex();
|
||||
|
||||
module.exports = new Mutex();
|
||||
async function doExclusively(func) {
|
||||
const releaseMutex = await instance.acquire();
|
||||
|
||||
try {
|
||||
await func();
|
||||
}
|
||||
finally {
|
||||
releaseMutex();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
doExclusively
|
||||
};
|
||||
Reference in New Issue
Block a user