From 0acbf30b0346f49c0ee8f5161fb00b4eca8e1a0c Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Mon, 20 Oct 2025 01:20:28 +0300 Subject: [PATCH] Fix migrations. Thanks to xet7 ! --- server/cronJobStorage.js | 18 ++++++++++++++ server/cronMigrationManager.js | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/server/cronJobStorage.js b/server/cronJobStorage.js index 76b659e1b..18c0b0150 100644 --- a/server/cronJobStorage.js +++ b/server/cronJobStorage.js @@ -369,6 +369,24 @@ class CronJobStorage { completedSteps: jobSteps.filter(step => step.status === 'completed').length }; } + + /** + * Clear all jobs from storage + */ + clearAllJobs() { + try { + // Clear all collections + CronJobStatus.remove({}); + CronJobSteps.remove({}); + CronJobQueue.remove({}); + + console.log('All cron job data cleared from storage'); + return { success: true, message: 'All cron job data cleared' }; + } catch (error) { + console.error('Error clearing cron job storage:', error); + return { success: false, error: error.message }; + } + } } // Export singleton instance diff --git a/server/cronMigrationManager.js b/server/cronMigrationManager.js index dd85c3743..34c4e7781 100644 --- a/server/cronMigrationManager.js +++ b/server/cronMigrationManager.js @@ -1308,6 +1308,41 @@ class CronMigrationManager { return stats; } + /** + * Clear all cron jobs and restart migration system + */ + clearAllCronJobs() { + try { + // Stop all existing cron jobs + if (SyncedCron && SyncedCron.jobs) { + SyncedCron.jobs.forEach(job => { + try { + SyncedCron.remove(job.name); + } catch (error) { + console.warn(`Failed to remove cron job ${job.name}:`, error.message); + } + }); + } + + // Clear job storage + cronJobStorage.clearAllJobs(); + + // Reset migration steps + this.migrationSteps = this.initializeMigrationSteps(); + this.currentStepIndex = 0; + this.isRunning = false; + + // Restart the migration system + this.initialize(); + + console.log('All cron jobs cleared and migration system restarted'); + return { success: true, message: 'All cron jobs cleared and migration system restarted' }; + } catch (error) { + console.error('Error clearing cron jobs:', error); + return { success: false, error: error.message }; + } + } + } // Export singleton instance @@ -1446,6 +1481,14 @@ Meteor.methods({ return cronJobStorage.getSystemResources(); }, + 'cron.clearAllJobs'() { + if (!this.userId) { + throw new Meteor.Error('not-authorized'); + } + + return cronMigrationManager.clearAllCronJobs(); + }, + 'cron.pauseJob'(jobId) { if (!this.userId) { throw new Meteor.Error('not-authorized');