mirror of
https://github.com/zadam/trilium.git
synced 2026-03-10 10:23:41 +01:00
refactor(server): don't set up other timers on module init
This commit is contained in:
parent
3c22ab8c9c
commit
d301e56216
@ -99,16 +99,16 @@ export default async function buildApp() {
|
||||
custom.register(app);
|
||||
error_handlers.register(app);
|
||||
|
||||
// triggers sync timer
|
||||
await import("./services/sync.js");
|
||||
const { startSyncTimer } = await import("./services/sync.js");
|
||||
startSyncTimer();
|
||||
|
||||
// triggers backup timer
|
||||
await import("./services/backup.js");
|
||||
|
||||
// trigger consistency checks timer
|
||||
await import("./services/consistency_checks.js");
|
||||
const { startConsistencyChecks } = await import("./services/consistency_checks.js");
|
||||
startConsistencyChecks();
|
||||
|
||||
await import("./services/scheduler.js");
|
||||
const { startScheduler } = await import("./services/scheduler.js");
|
||||
startScheduler();
|
||||
|
||||
startScheduledCleanup();
|
||||
|
||||
|
||||
@ -953,12 +953,14 @@ function runEntityChangesChecks() {
|
||||
consistencyChecks.findEntityChangeIssues();
|
||||
}
|
||||
|
||||
sqlInit.dbReady.then(() => {
|
||||
setInterval(cls.wrap(runPeriodicChecks), 60 * 60 * 1000);
|
||||
export function startConsistencyChecks() {
|
||||
sqlInit.dbReady.then(() => {
|
||||
setInterval(cls.wrap(runPeriodicChecks), 60 * 60 * 1000);
|
||||
|
||||
// kickoff checks soon after startup (to not block the initial load)
|
||||
setTimeout(cls.wrap(runPeriodicChecks), 4 * 1000);
|
||||
});
|
||||
// kickoff checks soon after startup (to not block the initial load)
|
||||
setTimeout(cls.wrap(runPeriodicChecks), 4 * 1000);
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
runOnDemandChecks,
|
||||
|
||||
@ -35,39 +35,41 @@ function runNotesWithLabel(runAttrValue: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// If the database is already initialized, we need to check the hidden subtree. Otherwise, hidden subtree
|
||||
// is also checked before importing the demo.zip, so no need to do it again.
|
||||
if (sqlInit.isDbInitialized()) {
|
||||
console.log("Checking hidden subtree.");
|
||||
sqlInit.dbReady.then(() => cls.init(() => hiddenSubtreeService.checkHiddenSubtree()));
|
||||
}
|
||||
|
||||
// Periodic checks.
|
||||
sqlInit.dbReady.then(() => {
|
||||
if (!process.env.TRILIUM_SAFE_MODE) {
|
||||
setTimeout(
|
||||
cls.wrap(() => runNotesWithLabel("backendStartup")),
|
||||
10 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => runNotesWithLabel("hourly")),
|
||||
3600 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => runNotesWithLabel("daily")),
|
||||
24 * 3600 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => hiddenSubtreeService.checkHiddenSubtree()),
|
||||
7 * 3600 * 1000
|
||||
);
|
||||
export function startScheduler() {
|
||||
// If the database is already initialized, we need to check the hidden subtree. Otherwise, hidden subtree
|
||||
// is also checked before importing the demo.zip, so no need to do it again.
|
||||
if (sqlInit.isDbInitialized()) {
|
||||
console.log("Checking hidden subtree.");
|
||||
sqlInit.dbReady.then(() => cls.init(() => hiddenSubtreeService.checkHiddenSubtree()));
|
||||
}
|
||||
|
||||
setInterval(() => checkProtectedSessionExpiration(), 30000);
|
||||
});
|
||||
// Periodic checks.
|
||||
sqlInit.dbReady.then(() => {
|
||||
if (!process.env.TRILIUM_SAFE_MODE) {
|
||||
setTimeout(
|
||||
cls.wrap(() => runNotesWithLabel("backendStartup")),
|
||||
10 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => runNotesWithLabel("hourly")),
|
||||
3600 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => runNotesWithLabel("daily")),
|
||||
24 * 3600 * 1000
|
||||
);
|
||||
|
||||
setInterval(
|
||||
cls.wrap(() => hiddenSubtreeService.checkHiddenSubtree()),
|
||||
7 * 3600 * 1000
|
||||
);
|
||||
}
|
||||
|
||||
setInterval(() => checkProtectedSessionExpiration(), 30000);
|
||||
});
|
||||
}
|
||||
|
||||
function checkProtectedSessionExpiration() {
|
||||
const protectedSessionTimeout = options.getOptionInt("protectedSessionTimeout");
|
||||
|
||||
@ -446,15 +446,17 @@ function getOutstandingPullCount() {
|
||||
return outstandingPullCount;
|
||||
}
|
||||
|
||||
becca_loader.beccaLoaded.then(() => {
|
||||
setInterval(cls.wrap(sync), 60000);
|
||||
export function startSyncTimer() {
|
||||
becca_loader.beccaLoaded.then(() => {
|
||||
setInterval(cls.wrap(sync), 60000);
|
||||
|
||||
// kickoff initial sync immediately, but should happen after initial consistency checks
|
||||
setTimeout(cls.wrap(sync), 5000);
|
||||
// kickoff initial sync immediately, but should happen after initial consistency checks
|
||||
setTimeout(cls.wrap(sync), 5000);
|
||||
|
||||
// called just so ws.setLastSyncedPush() is called
|
||||
getLastSyncedPush();
|
||||
});
|
||||
// called just so ws.setLastSyncedPush() is called
|
||||
getLastSyncedPush();
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
sync,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user