diff --git a/src/app/api/settings/auto-sync/route.ts b/src/app/api/settings/auto-sync/route.ts index 5002df1..f912a27 100644 --- a/src/app/api/settings/auto-sync/route.ts +++ b/src/app/api/settings/auto-sync/route.ts @@ -7,7 +7,6 @@ import { isValidCron } from 'cron-validator'; export async function POST(request: NextRequest) { try { const settings = await request.json(); - console.log('Received auto-sync settings:', settings); if (!settings || typeof settings !== 'object') { return NextResponse.json( @@ -46,14 +45,11 @@ export async function POST(request: NextRequest) { // Validate sync interval type if (!['predefined', 'custom'].includes(settings.syncIntervalType)) { - console.log('Invalid syncIntervalType:', settings.syncIntervalType); return NextResponse.json( { error: 'syncIntervalType must be "predefined" or "custom"' }, { status: 400 } ); } - - console.log('Sync interval validation - type:', settings.syncIntervalType, 'cron:', settings.syncIntervalCron); // Validate predefined interval if (settings.syncIntervalType === 'predefined') { @@ -69,7 +65,6 @@ export async function POST(request: NextRequest) { // Validate custom cron expression if (settings.syncIntervalType === 'custom') { if (!settings.syncIntervalCron || typeof settings.syncIntervalCron !== 'string' || settings.syncIntervalCron.trim() === '') { - console.log('Custom sync interval type but no cron expression provided, falling back to predefined'); // Fallback to predefined if custom is selected but no cron expression settings.syncIntervalType = 'predefined'; settings.syncIntervalPredefined = settings.syncIntervalPredefined || '1hour'; @@ -159,10 +154,7 @@ export async function POST(request: NextRequest) { } // Write back to .env file - console.log('Writing to .env file:', envPath); - console.log('New .env content:', envContent); fs.writeFileSync(envPath, envContent); - console.log('Successfully wrote to .env file'); // Reschedule auto-sync service with new settings try { @@ -177,17 +169,14 @@ export async function POST(request: NextRequest) { } // Update the global service instance with new settings - console.log('Updating global service instance with settings:', settings); autoSyncService.saveSettings(settings); if (settings.autoSyncEnabled) { - console.log('Enabling auto-sync...'); autoSyncService.scheduleAutoSync(); - console.log('Auto-sync rescheduled with new settings'); } else { - console.log('Disabling auto-sync...'); autoSyncService.stopAutoSync(); - console.log('Auto-sync stopped'); + // Ensure the service is completely stopped and won't restart + autoSyncService.isRunning = false; } } catch (error) { console.error('Error rescheduling auto-sync service:', error); diff --git a/src/server/api/routers/scripts.ts b/src/server/api/routers/scripts.ts index 2b5b61e..0c394b2 100644 --- a/src/server/api/routers/scripts.ts +++ b/src/server/api/routers/scripts.ts @@ -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'); } diff --git a/src/server/services/autoSyncService.js b/src/server/services/autoSyncService.js index e7c9b2b..cade526 100644 --- a/src/server/services/autoSyncService.js +++ b/src/server/services/autoSyncService.js @@ -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(); }, {