Browse Source

Fix migrations.

Thanks to xet7 !
Lauri Ojansivu 2 days ago
parent
commit
0acbf30b03
2 changed files with 61 additions and 0 deletions
  1. 18 0
      server/cronJobStorage.js
  2. 43 0
      server/cronMigrationManager.js

+ 18 - 0
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

+ 43 - 0
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');