Fix autosync continuing to run after being disabled
- Add defensive check in cron job execution to stop if autosync is disabled - Ensure isRunning flag is set to false when stopping autosync - Add logging to show when autosync is disabled and not scheduling - Fix both API route and TRPC router to properly stop service - Prevent multiple cron jobs from running simultaneously This fixes the issue where autosync would continue running even after being disabled in the GUI, causing rate limit errors and unwanted syncs.
This commit is contained in:
@@ -523,6 +523,8 @@ export const scriptsRouter = createTRPCRouter({
|
||||
console.log('Auto-sync rescheduled with new settings');
|
||||
} else {
|
||||
autoSyncService.stopAutoSync();
|
||||
// Ensure the service is completely stopped and won't restart
|
||||
autoSyncService.isRunning = false;
|
||||
console.log('Auto-sync stopped');
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ export class AutoSyncService {
|
||||
|
||||
const settings = this.loadSettings();
|
||||
if (!settings.autoSyncEnabled) {
|
||||
console.log('Auto-sync is disabled, not scheduling cron job');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -240,6 +241,14 @@ export class AutoSyncService {
|
||||
return;
|
||||
}
|
||||
|
||||
// Double-check that autosync is still enabled before executing
|
||||
const currentSettings = this.loadSettings();
|
||||
if (!currentSettings.autoSyncEnabled) {
|
||||
console.log('Auto-sync has been disabled, stopping cron job');
|
||||
this.stopAutoSync();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Starting scheduled auto-sync...');
|
||||
await this.executeAutoSync();
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user