cronMigrationManager.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  1. /**
  2. * Cron Migration Manager
  3. * Manages database migrations as cron jobs using percolate:synced-cron
  4. */
  5. import { Meteor } from 'meteor/meteor';
  6. import { SyncedCron } from 'meteor/percolate:synced-cron';
  7. import { ReactiveVar } from 'meteor/reactive-var';
  8. import { cronJobStorage } from './cronJobStorage';
  9. // Server-side reactive variables for cron migration progress
  10. export const cronMigrationProgress = new ReactiveVar(0);
  11. export const cronMigrationStatus = new ReactiveVar('');
  12. export const cronMigrationCurrentStep = new ReactiveVar('');
  13. export const cronMigrationSteps = new ReactiveVar([]);
  14. export const cronIsMigrating = new ReactiveVar(false);
  15. export const cronJobs = new ReactiveVar([]);
  16. // Board-specific operation tracking
  17. export const boardOperations = new ReactiveVar(new Map());
  18. export const boardOperationProgress = new ReactiveVar(new Map());
  19. class CronMigrationManager {
  20. constructor() {
  21. this.migrationSteps = this.initializeMigrationSteps();
  22. this.currentStepIndex = 0;
  23. this.startTime = null;
  24. this.isRunning = false;
  25. this.jobProcessor = null;
  26. this.processingInterval = null;
  27. }
  28. /**
  29. * Initialize migration steps as cron jobs
  30. */
  31. initializeMigrationSteps() {
  32. return [
  33. {
  34. id: 'board-background-color',
  35. name: 'Board Background Colors',
  36. description: 'Setting up board background colors',
  37. weight: 1,
  38. completed: false,
  39. progress: 0,
  40. cronName: 'migration_board_background_color',
  41. schedule: 'every 1 minute', // Will be changed to 'once' when triggered
  42. status: 'stopped'
  43. },
  44. {
  45. id: 'add-cardcounterlist-allowed',
  46. name: 'Card Counter List Settings',
  47. description: 'Adding card counter list permissions',
  48. weight: 1,
  49. completed: false,
  50. progress: 0,
  51. cronName: 'migration_card_counter_list',
  52. schedule: 'every 1 minute',
  53. status: 'stopped'
  54. },
  55. {
  56. id: 'add-boardmemberlist-allowed',
  57. name: 'Board Member List Settings',
  58. description: 'Adding board member list permissions',
  59. weight: 1,
  60. completed: false,
  61. progress: 0,
  62. cronName: 'migration_board_member_list',
  63. schedule: 'every 1 minute',
  64. status: 'stopped'
  65. },
  66. {
  67. id: 'lowercase-board-permission',
  68. name: 'Board Permission Standardization',
  69. description: 'Converting board permissions to lowercase',
  70. weight: 1,
  71. completed: false,
  72. progress: 0,
  73. cronName: 'migration_lowercase_permission',
  74. schedule: 'every 1 minute',
  75. status: 'stopped'
  76. },
  77. {
  78. id: 'change-attachments-type-for-non-images',
  79. name: 'Attachment Type Standardization',
  80. description: 'Updating attachment types for non-images',
  81. weight: 2,
  82. completed: false,
  83. progress: 0,
  84. cronName: 'migration_attachment_types',
  85. schedule: 'every 1 minute',
  86. status: 'stopped'
  87. },
  88. {
  89. id: 'card-covers',
  90. name: 'Card Covers System',
  91. description: 'Setting up card cover functionality',
  92. weight: 2,
  93. completed: false,
  94. progress: 0,
  95. cronName: 'migration_card_covers',
  96. schedule: 'every 1 minute',
  97. status: 'stopped'
  98. },
  99. {
  100. id: 'use-css-class-for-boards-colors',
  101. name: 'Board Color CSS Classes',
  102. description: 'Converting board colors to CSS classes',
  103. weight: 2,
  104. completed: false,
  105. progress: 0,
  106. cronName: 'migration_board_color_css',
  107. schedule: 'every 1 minute',
  108. status: 'stopped'
  109. },
  110. {
  111. id: 'denormalize-star-number-per-board',
  112. name: 'Board Star Counts',
  113. description: 'Calculating star counts per board',
  114. weight: 3,
  115. completed: false,
  116. progress: 0,
  117. cronName: 'migration_star_numbers',
  118. schedule: 'every 1 minute',
  119. status: 'stopped'
  120. },
  121. {
  122. id: 'add-member-isactive-field',
  123. name: 'Member Activity Status',
  124. description: 'Adding member activity tracking',
  125. weight: 2,
  126. completed: false,
  127. progress: 0,
  128. cronName: 'migration_member_activity',
  129. schedule: 'every 1 minute',
  130. status: 'stopped'
  131. },
  132. {
  133. id: 'add-sort-checklists',
  134. name: 'Checklist Sorting',
  135. description: 'Adding sort order to checklists',
  136. weight: 2,
  137. completed: false,
  138. progress: 0,
  139. cronName: 'migration_sort_checklists',
  140. schedule: 'every 1 minute',
  141. status: 'stopped'
  142. },
  143. {
  144. id: 'add-swimlanes',
  145. name: 'Swimlanes System',
  146. description: 'Setting up swimlanes functionality',
  147. weight: 4,
  148. completed: false,
  149. progress: 0,
  150. cronName: 'migration_swimlanes',
  151. schedule: 'every 1 minute',
  152. status: 'stopped'
  153. },
  154. {
  155. id: 'add-views',
  156. name: 'Board Views',
  157. description: 'Adding board view options',
  158. weight: 2,
  159. completed: false,
  160. progress: 0,
  161. cronName: 'migration_views',
  162. schedule: 'every 1 minute',
  163. status: 'stopped'
  164. },
  165. {
  166. id: 'add-checklist-items',
  167. name: 'Checklist Items',
  168. description: 'Setting up checklist items system',
  169. weight: 3,
  170. completed: false,
  171. progress: 0,
  172. cronName: 'migration_checklist_items',
  173. schedule: 'every 1 minute',
  174. status: 'stopped'
  175. },
  176. {
  177. id: 'add-card-types',
  178. name: 'Card Types',
  179. description: 'Adding card type functionality',
  180. weight: 2,
  181. completed: false,
  182. progress: 0,
  183. cronName: 'migration_card_types',
  184. schedule: 'every 1 minute',
  185. status: 'stopped'
  186. },
  187. {
  188. id: 'add-custom-fields-to-cards',
  189. name: 'Custom Fields',
  190. description: 'Adding custom fields to cards',
  191. weight: 3,
  192. completed: false,
  193. progress: 0,
  194. cronName: 'migration_custom_fields',
  195. schedule: 'every 1 minute',
  196. status: 'stopped'
  197. },
  198. {
  199. id: 'migrate-attachments-collectionFS-to-ostrioFiles',
  200. name: 'Migrate Attachments to Meteor-Files',
  201. description: 'Migrating attachments from CollectionFS to Meteor-Files',
  202. weight: 8,
  203. completed: false,
  204. progress: 0,
  205. cronName: 'migration_attachments_collectionfs',
  206. schedule: 'every 1 minute',
  207. status: 'stopped'
  208. },
  209. {
  210. id: 'migrate-avatars-collectionFS-to-ostrioFiles',
  211. name: 'Migrate Avatars to Meteor-Files',
  212. description: 'Migrating avatars from CollectionFS to Meteor-Files',
  213. weight: 6,
  214. completed: false,
  215. progress: 0,
  216. cronName: 'migration_avatars_collectionfs',
  217. schedule: 'every 1 minute',
  218. status: 'stopped'
  219. },
  220. {
  221. id: 'migrate-lists-to-per-swimlane',
  222. name: 'Migrate Lists to Per-Swimlane',
  223. description: 'Migrating lists to per-swimlane structure',
  224. weight: 5,
  225. completed: false,
  226. progress: 0,
  227. cronName: 'migration_lists_per_swimlane',
  228. schedule: 'every 1 minute',
  229. status: 'stopped'
  230. }
  231. ];
  232. }
  233. /**
  234. * Initialize all migration cron jobs
  235. */
  236. initializeCronJobs() {
  237. this.migrationSteps.forEach(step => {
  238. this.createCronJob(step);
  239. });
  240. // Start job processor
  241. this.startJobProcessor();
  242. // Update cron jobs list after a short delay to allow SyncedCron to initialize
  243. Meteor.setTimeout(() => {
  244. this.updateCronJobsList();
  245. }, 1000);
  246. }
  247. /**
  248. * Start the job processor for CPU-aware job execution
  249. */
  250. startJobProcessor() {
  251. if (this.processingInterval) {
  252. return; // Already running
  253. }
  254. this.processingInterval = Meteor.setInterval(() => {
  255. this.processJobQueue();
  256. }, 5000); // Check every 5 seconds
  257. // Cron job processor started with CPU throttling
  258. }
  259. /**
  260. * Stop the job processor
  261. */
  262. stopJobProcessor() {
  263. if (this.processingInterval) {
  264. Meteor.clearInterval(this.processingInterval);
  265. this.processingInterval = null;
  266. }
  267. }
  268. /**
  269. * Process the job queue with CPU throttling
  270. */
  271. async processJobQueue() {
  272. const canStart = cronJobStorage.canStartNewJob();
  273. if (!canStart.canStart) {
  274. console.log(`Cannot start new job: ${canStart.reason}`);
  275. return;
  276. }
  277. const nextJob = cronJobStorage.getNextJob();
  278. if (!nextJob) {
  279. return; // No jobs in queue
  280. }
  281. // Start the job
  282. await this.executeJob(nextJob);
  283. }
  284. /**
  285. * Execute a job from the queue
  286. */
  287. async executeJob(queueJob) {
  288. const { jobId, jobType, jobData } = queueJob;
  289. try {
  290. // Update queue status to running
  291. cronJobStorage.updateQueueStatus(jobId, 'running', { startedAt: new Date() });
  292. // Save job status
  293. cronJobStorage.saveJobStatus(jobId, {
  294. jobType,
  295. status: 'running',
  296. progress: 0,
  297. startedAt: new Date(),
  298. ...jobData
  299. });
  300. // Execute based on job type
  301. if (jobType === 'migration') {
  302. await this.executeMigrationJob(jobId, jobData);
  303. } else if (jobType === 'board_operation') {
  304. await this.executeBoardOperationJob(jobId, jobData);
  305. } else if (jobType === 'board_migration') {
  306. await this.executeBoardMigrationJob(jobId, jobData);
  307. } else {
  308. throw new Error(`Unknown job type: ${jobType}`);
  309. }
  310. // Mark as completed
  311. cronJobStorage.updateQueueStatus(jobId, 'completed', { completedAt: new Date() });
  312. cronJobStorage.saveJobStatus(jobId, {
  313. status: 'completed',
  314. progress: 100,
  315. completedAt: new Date()
  316. });
  317. } catch (error) {
  318. console.error(`Job ${jobId} failed:`, error);
  319. // Mark as failed
  320. cronJobStorage.updateQueueStatus(jobId, 'failed', {
  321. failedAt: new Date(),
  322. error: error.message
  323. });
  324. cronJobStorage.saveJobStatus(jobId, {
  325. status: 'failed',
  326. error: error.message,
  327. failedAt: new Date()
  328. });
  329. }
  330. }
  331. /**
  332. * Execute a migration job
  333. */
  334. async executeMigrationJob(jobId, jobData) {
  335. const { stepId } = jobData;
  336. const step = this.migrationSteps.find(s => s.id === stepId);
  337. if (!step) {
  338. throw new Error(`Migration step ${stepId} not found`);
  339. }
  340. // Create steps for this migration
  341. const steps = this.createMigrationSteps(step);
  342. for (let i = 0; i < steps.length; i++) {
  343. const stepData = steps[i];
  344. // Save step status
  345. cronJobStorage.saveJobStep(jobId, i, {
  346. stepName: stepData.name,
  347. status: 'running',
  348. progress: 0
  349. });
  350. // Execute step
  351. await this.executeMigrationStep(jobId, i, stepData);
  352. // Mark step as completed
  353. cronJobStorage.saveJobStep(jobId, i, {
  354. status: 'completed',
  355. progress: 100,
  356. completedAt: new Date()
  357. });
  358. // Update overall progress
  359. const progress = Math.round(((i + 1) / steps.length) * 100);
  360. cronJobStorage.saveJobStatus(jobId, { progress });
  361. }
  362. }
  363. /**
  364. * Create migration steps for a job
  365. */
  366. createMigrationSteps(step) {
  367. const steps = [];
  368. switch (step.id) {
  369. case 'board-background-color':
  370. steps.push(
  371. { name: 'Initialize board colors', duration: 1000 },
  372. { name: 'Update board documents', duration: 2000 },
  373. { name: 'Finalize changes', duration: 500 }
  374. );
  375. break;
  376. case 'add-cardcounterlist-allowed':
  377. steps.push(
  378. { name: 'Add card counter permissions', duration: 800 },
  379. { name: 'Update existing boards', duration: 1500 },
  380. { name: 'Verify permissions', duration: 700 }
  381. );
  382. break;
  383. case 'migrate-attachments-collectionFS-to-ostrioFiles':
  384. steps.push(
  385. { name: 'Scan CollectionFS attachments', duration: 2000 },
  386. { name: 'Create Meteor-Files records', duration: 3000 },
  387. { name: 'Migrate file data', duration: 5000 },
  388. { name: 'Update references', duration: 2000 },
  389. { name: 'Cleanup old data', duration: 1000 }
  390. );
  391. break;
  392. default:
  393. steps.push(
  394. { name: `Execute ${step.name}`, duration: 2000 },
  395. { name: 'Verify changes', duration: 1000 }
  396. );
  397. }
  398. return steps;
  399. }
  400. /**
  401. * Execute a migration step
  402. */
  403. async executeMigrationStep(jobId, stepIndex, stepData) {
  404. const { name, duration } = stepData;
  405. // Simulate step execution with progress updates
  406. const progressSteps = 10;
  407. for (let i = 0; i <= progressSteps; i++) {
  408. const progress = Math.round((i / progressSteps) * 100);
  409. // Update step progress
  410. cronJobStorage.saveJobStep(jobId, stepIndex, {
  411. progress,
  412. currentAction: `Executing: ${name} (${progress}%)`
  413. });
  414. // Simulate work
  415. await new Promise(resolve => setTimeout(resolve, duration / progressSteps));
  416. }
  417. }
  418. /**
  419. * Execute a board operation job
  420. */
  421. async executeBoardOperationJob(jobId, jobData) {
  422. const { operationType, operationData } = jobData;
  423. // Use existing board operation logic
  424. await this.executeBoardOperation(jobId, operationType, operationData);
  425. }
  426. /**
  427. * Execute a board migration job
  428. */
  429. async executeBoardMigrationJob(jobId, jobData) {
  430. const { boardId, boardTitle, migrationType } = jobData;
  431. try {
  432. // Starting board migration
  433. // Create migration steps for this board
  434. const steps = this.createBoardMigrationSteps(boardId, migrationType);
  435. for (let i = 0; i < steps.length; i++) {
  436. const stepData = steps[i];
  437. // Save step status
  438. cronJobStorage.saveJobStep(jobId, i, {
  439. stepName: stepData.name,
  440. status: 'running',
  441. progress: 0,
  442. boardId: boardId
  443. });
  444. // Execute step
  445. await this.executeBoardMigrationStep(jobId, i, stepData, boardId);
  446. // Mark step as completed
  447. cronJobStorage.saveJobStep(jobId, i, {
  448. status: 'completed',
  449. progress: 100,
  450. completedAt: new Date()
  451. });
  452. // Update overall progress
  453. const progress = Math.round(((i + 1) / steps.length) * 100);
  454. cronJobStorage.saveJobStatus(jobId, { progress });
  455. }
  456. // Mark board as migrated
  457. this.markBoardAsMigrated(boardId, migrationType);
  458. // Completed board migration
  459. } catch (error) {
  460. console.error(`Board migration failed for ${boardId}:`, error);
  461. throw error;
  462. }
  463. }
  464. /**
  465. * Create migration steps for a board
  466. */
  467. createBoardMigrationSteps(boardId, migrationType) {
  468. const steps = [];
  469. if (migrationType === 'full_board_migration') {
  470. steps.push(
  471. { name: 'Check board structure', duration: 500, type: 'validation' },
  472. { name: 'Migrate lists to swimlanes', duration: 2000, type: 'lists' },
  473. { name: 'Migrate attachments', duration: 3000, type: 'attachments' },
  474. { name: 'Update board metadata', duration: 1000, type: 'metadata' },
  475. { name: 'Verify migration', duration: 1000, type: 'verification' }
  476. );
  477. } else {
  478. // Default migration steps
  479. steps.push(
  480. { name: 'Initialize board migration', duration: 1000, type: 'init' },
  481. { name: 'Execute migration', duration: 2000, type: 'migration' },
  482. { name: 'Finalize changes', duration: 1000, type: 'finalize' }
  483. );
  484. }
  485. return steps;
  486. }
  487. /**
  488. * Execute a board migration step
  489. */
  490. async executeBoardMigrationStep(jobId, stepIndex, stepData, boardId) {
  491. const { name, duration, type } = stepData;
  492. // Simulate step execution with progress updates
  493. const progressSteps = 10;
  494. for (let i = 0; i <= progressSteps; i++) {
  495. const progress = Math.round((i / progressSteps) * 100);
  496. // Update step progress
  497. cronJobStorage.saveJobStep(jobId, stepIndex, {
  498. progress,
  499. currentAction: `Executing: ${name} (${progress}%)`
  500. });
  501. // Simulate work based on step type
  502. await this.simulateBoardMigrationWork(type, duration / progressSteps);
  503. }
  504. }
  505. /**
  506. * Simulate board migration work
  507. */
  508. async simulateBoardMigrationWork(stepType, duration) {
  509. // Simulate different types of migration work
  510. switch (stepType) {
  511. case 'validation':
  512. // Quick validation
  513. await new Promise(resolve => setTimeout(resolve, duration * 0.5));
  514. break;
  515. case 'lists':
  516. // List migration work
  517. await new Promise(resolve => setTimeout(resolve, duration));
  518. break;
  519. case 'attachments':
  520. // Attachment migration work
  521. await new Promise(resolve => setTimeout(resolve, duration * 1.2));
  522. break;
  523. case 'metadata':
  524. // Metadata update work
  525. await new Promise(resolve => setTimeout(resolve, duration * 0.8));
  526. break;
  527. case 'verification':
  528. // Verification work
  529. await new Promise(resolve => setTimeout(resolve, duration * 0.6));
  530. break;
  531. default:
  532. // Default work
  533. await new Promise(resolve => setTimeout(resolve, duration));
  534. }
  535. }
  536. /**
  537. * Mark a board as migrated
  538. */
  539. markBoardAsMigrated(boardId, migrationType) {
  540. try {
  541. // Update board with migration markers
  542. const updateQuery = {
  543. 'migrationMarkers.fullMigrationCompleted': true,
  544. 'migrationMarkers.lastMigration': new Date(),
  545. 'migrationMarkers.migrationType': migrationType
  546. };
  547. // Update the board document
  548. if (typeof Boards !== 'undefined') {
  549. Boards.update(boardId, { $set: updateQuery });
  550. }
  551. console.log(`Marked board ${boardId} as migrated`);
  552. } catch (error) {
  553. console.error(`Error marking board ${boardId} as migrated:`, error);
  554. }
  555. }
  556. /**
  557. * Create a cron job for a migration step
  558. */
  559. createCronJob(step) {
  560. SyncedCron.add({
  561. name: step.cronName,
  562. schedule: (parser) => parser.text(step.schedule),
  563. job: () => {
  564. this.runMigrationStep(step);
  565. },
  566. });
  567. }
  568. /**
  569. * Run a migration step
  570. */
  571. async runMigrationStep(step) {
  572. try {
  573. // Starting migration step
  574. cronMigrationCurrentStep.set(step.name);
  575. cronMigrationStatus.set(`Running: ${step.description}`);
  576. cronIsMigrating.set(true);
  577. // Simulate migration progress
  578. const progressSteps = 10;
  579. for (let i = 0; i <= progressSteps; i++) {
  580. step.progress = (i / progressSteps) * 100;
  581. this.updateProgress();
  582. // Simulate work
  583. await new Promise(resolve => setTimeout(resolve, 100));
  584. }
  585. // Mark as completed
  586. step.completed = true;
  587. step.progress = 100;
  588. step.status = 'completed';
  589. // Completed migration step
  590. // Update progress
  591. this.updateProgress();
  592. } catch (error) {
  593. console.error(`Migration ${step.name} failed:`, error);
  594. step.status = 'error';
  595. cronMigrationStatus.set(`Migration failed: ${error.message}`);
  596. }
  597. }
  598. /**
  599. * Start all migrations using job queue
  600. */
  601. async startAllMigrations() {
  602. if (this.isRunning) {
  603. return;
  604. }
  605. this.isRunning = true;
  606. cronIsMigrating.set(true);
  607. cronMigrationStatus.set('Adding migrations to job queue...');
  608. this.startTime = Date.now();
  609. try {
  610. // Add all migration steps to the job queue
  611. for (let i = 0; i < this.migrationSteps.length; i++) {
  612. const step = this.migrationSteps[i];
  613. if (step.completed) {
  614. continue; // Skip already completed steps
  615. }
  616. // Add to job queue
  617. const jobId = `migration_${step.id}_${Date.now()}`;
  618. cronJobStorage.addToQueue(jobId, 'migration', step.weight, {
  619. stepId: step.id,
  620. stepName: step.name,
  621. stepDescription: step.description
  622. });
  623. // Save initial job status
  624. cronJobStorage.saveJobStatus(jobId, {
  625. jobType: 'migration',
  626. status: 'pending',
  627. progress: 0,
  628. stepId: step.id,
  629. stepName: step.name,
  630. stepDescription: step.description
  631. });
  632. }
  633. cronMigrationStatus.set('Migrations added to queue. Processing will begin shortly...');
  634. // Start monitoring progress
  635. this.monitorMigrationProgress();
  636. } catch (error) {
  637. console.error('Failed to start migrations:', error);
  638. cronMigrationStatus.set(`Failed to start migrations: ${error.message}`);
  639. cronIsMigrating.set(false);
  640. this.isRunning = false;
  641. }
  642. }
  643. /**
  644. * Monitor migration progress
  645. */
  646. monitorMigrationProgress() {
  647. const monitorInterval = Meteor.setInterval(() => {
  648. const stats = cronJobStorage.getQueueStats();
  649. const incompleteJobs = cronJobStorage.getIncompleteJobs();
  650. // Update progress
  651. const totalJobs = stats.total;
  652. const completedJobs = stats.completed;
  653. const progress = totalJobs > 0 ? Math.round((completedJobs / totalJobs) * 100) : 0;
  654. cronMigrationProgress.set(progress);
  655. // Update status
  656. if (stats.running > 0) {
  657. const runningJob = incompleteJobs.find(job => job.status === 'running');
  658. if (runningJob) {
  659. cronMigrationCurrentStep.set(runningJob.stepName || 'Processing migration...');
  660. cronMigrationStatus.set(`Running: ${runningJob.stepName || 'Migration in progress'}`);
  661. }
  662. } else if (stats.pending > 0) {
  663. cronMigrationStatus.set(`${stats.pending} migrations pending in queue`);
  664. cronMigrationCurrentStep.set('Waiting for available resources...');
  665. } else if (stats.completed === totalJobs && totalJobs > 0) {
  666. // All migrations completed
  667. cronMigrationStatus.set('All migrations completed successfully!');
  668. cronMigrationProgress.set(100);
  669. cronMigrationCurrentStep.set('');
  670. // Clear status after delay
  671. setTimeout(() => {
  672. cronIsMigrating.set(false);
  673. cronMigrationStatus.set('');
  674. cronMigrationProgress.set(0);
  675. }, 3000);
  676. Meteor.clearInterval(monitorInterval);
  677. }
  678. }, 2000); // Check every 2 seconds
  679. }
  680. /**
  681. * Start a specific cron job
  682. */
  683. async startCronJob(cronName) {
  684. // Change schedule to run once
  685. const job = SyncedCron.jobs.find(j => j.name === cronName);
  686. if (job) {
  687. job.schedule = 'once';
  688. SyncedCron.start();
  689. }
  690. }
  691. /**
  692. * Wait for a cron job to complete
  693. */
  694. async waitForCronJobCompletion(step) {
  695. return new Promise((resolve) => {
  696. const checkInterval = setInterval(() => {
  697. if (step.completed || step.status === 'error') {
  698. clearInterval(checkInterval);
  699. resolve();
  700. }
  701. }, 1000);
  702. });
  703. }
  704. /**
  705. * Stop a specific cron job
  706. */
  707. stopCronJob(cronName) {
  708. SyncedCron.remove(cronName);
  709. const step = this.migrationSteps.find(s => s.cronName === cronName);
  710. if (step) {
  711. step.status = 'stopped';
  712. }
  713. this.updateCronJobsList();
  714. }
  715. /**
  716. * Pause a specific cron job
  717. */
  718. pauseCronJob(cronName) {
  719. SyncedCron.pause(cronName);
  720. const step = this.migrationSteps.find(s => s.cronName === cronName);
  721. if (step) {
  722. step.status = 'paused';
  723. }
  724. this.updateCronJobsList();
  725. }
  726. /**
  727. * Resume a specific cron job
  728. */
  729. resumeCronJob(cronName) {
  730. SyncedCron.resume(cronName);
  731. const step = this.migrationSteps.find(s => s.cronName === cronName);
  732. if (step) {
  733. step.status = 'running';
  734. }
  735. this.updateCronJobsList();
  736. }
  737. /**
  738. * Remove a cron job
  739. */
  740. removeCronJob(cronName) {
  741. SyncedCron.remove(cronName);
  742. this.migrationSteps = this.migrationSteps.filter(s => s.cronName !== cronName);
  743. this.updateCronJobsList();
  744. }
  745. /**
  746. * Add a new cron job
  747. */
  748. addCronJob(jobData) {
  749. const step = {
  750. id: jobData.id || `custom_${Date.now()}`,
  751. name: jobData.name,
  752. description: jobData.description,
  753. weight: jobData.weight || 1,
  754. completed: false,
  755. progress: 0,
  756. cronName: jobData.cronName || `custom_${Date.now()}`,
  757. schedule: jobData.schedule || 'every 1 minute',
  758. status: 'stopped'
  759. };
  760. this.migrationSteps.push(step);
  761. this.createCronJob(step);
  762. this.updateCronJobsList();
  763. }
  764. /**
  765. * Update progress variables
  766. */
  767. updateProgress() {
  768. const totalWeight = this.migrationSteps.reduce((total, step) => total + step.weight, 0);
  769. const completedWeight = this.migrationSteps.reduce((total, step) => {
  770. return total + (step.completed ? step.weight : step.progress * step.weight / 100);
  771. }, 0);
  772. const progress = Math.round((completedWeight / totalWeight) * 100);
  773. cronMigrationProgress.set(progress);
  774. cronMigrationSteps.set([...this.migrationSteps]);
  775. }
  776. /**
  777. * Update cron jobs list
  778. */
  779. updateCronJobsList() {
  780. // Check if SyncedCron is available and has jobs
  781. if (!SyncedCron || !SyncedCron.jobs || !Array.isArray(SyncedCron.jobs)) {
  782. // SyncedCron not available or no jobs yet
  783. cronJobs.set([]);
  784. return;
  785. }
  786. const jobs = SyncedCron.jobs.map(job => {
  787. const step = this.migrationSteps.find(s => s.cronName === job.name);
  788. return {
  789. name: job.name,
  790. schedule: job.schedule,
  791. status: step ? step.status : 'unknown',
  792. lastRun: job.lastRun,
  793. nextRun: job.nextRun,
  794. running: job.running
  795. };
  796. });
  797. cronJobs.set(jobs);
  798. }
  799. /**
  800. * Get all cron jobs
  801. */
  802. getAllCronJobs() {
  803. return cronJobs.get();
  804. }
  805. /**
  806. * Get migration steps
  807. */
  808. getMigrationSteps() {
  809. return this.migrationSteps;
  810. }
  811. /**
  812. * Start a long-running operation for a specific board
  813. */
  814. startBoardOperation(boardId, operationType, operationData) {
  815. const operationId = `${boardId}_${operationType}_${Date.now()}`;
  816. // Add to job queue
  817. cronJobStorage.addToQueue(operationId, 'board_operation', 3, {
  818. boardId,
  819. operationType,
  820. operationData
  821. });
  822. // Save initial job status
  823. cronJobStorage.saveJobStatus(operationId, {
  824. jobType: 'board_operation',
  825. status: 'pending',
  826. progress: 0,
  827. boardId,
  828. operationType,
  829. operationData,
  830. createdAt: new Date()
  831. });
  832. // Update board operations map for backward compatibility
  833. const operation = {
  834. id: operationId,
  835. boardId: boardId,
  836. type: operationType,
  837. data: operationData,
  838. status: 'pending',
  839. progress: 0,
  840. startTime: new Date(),
  841. endTime: null,
  842. error: null
  843. };
  844. const operations = boardOperations.get();
  845. operations.set(operationId, operation);
  846. boardOperations.set(operations);
  847. return operationId;
  848. }
  849. /**
  850. * Execute a board operation
  851. */
  852. async executeBoardOperation(operationId, operationType, operationData) {
  853. const operations = boardOperations.get();
  854. const operation = operations.get(operationId);
  855. if (!operation) {
  856. console.error(`Operation ${operationId} not found`);
  857. return;
  858. }
  859. try {
  860. console.log(`Starting board operation: ${operationType} for board ${operation.boardId}`);
  861. // Update operation status
  862. operation.status = 'running';
  863. operation.progress = 0;
  864. this.updateBoardOperation(operationId, operation);
  865. // Execute the specific operation
  866. switch (operationType) {
  867. case 'copy_board':
  868. await this.copyBoard(operationId, operationData);
  869. break;
  870. case 'move_board':
  871. await this.moveBoard(operationId, operationData);
  872. break;
  873. case 'copy_swimlane':
  874. await this.copySwimlane(operationId, operationData);
  875. break;
  876. case 'move_swimlane':
  877. await this.moveSwimlane(operationId, operationData);
  878. break;
  879. case 'copy_list':
  880. await this.copyList(operationId, operationData);
  881. break;
  882. case 'move_list':
  883. await this.moveList(operationId, operationData);
  884. break;
  885. case 'copy_card':
  886. await this.copyCard(operationId, operationData);
  887. break;
  888. case 'move_card':
  889. await this.moveCard(operationId, operationData);
  890. break;
  891. case 'copy_checklist':
  892. await this.copyChecklist(operationId, operationData);
  893. break;
  894. case 'move_checklist':
  895. await this.moveChecklist(operationId, operationData);
  896. break;
  897. default:
  898. throw new Error(`Unknown operation type: ${operationType}`);
  899. }
  900. // Mark as completed
  901. operation.status = 'completed';
  902. operation.progress = 100;
  903. operation.endTime = new Date();
  904. this.updateBoardOperation(operationId, operation);
  905. console.log(`Completed board operation: ${operationType} for board ${operation.boardId}`);
  906. } catch (error) {
  907. console.error(`Board operation ${operationType} failed:`, error);
  908. operation.status = 'error';
  909. operation.error = error.message;
  910. operation.endTime = new Date();
  911. this.updateBoardOperation(operationId, operation);
  912. }
  913. }
  914. /**
  915. * Update board operation progress
  916. */
  917. updateBoardOperation(operationId, operation) {
  918. const operations = boardOperations.get();
  919. operations.set(operationId, operation);
  920. boardOperations.set(operations);
  921. // Update progress map
  922. const progressMap = boardOperationProgress.get();
  923. progressMap.set(operationId, {
  924. progress: operation.progress,
  925. status: operation.status,
  926. error: operation.error
  927. });
  928. boardOperationProgress.set(progressMap);
  929. }
  930. /**
  931. * Copy board operation
  932. */
  933. async copyBoard(operationId, data) {
  934. const { sourceBoardId, targetBoardId, copyOptions } = data;
  935. const operation = boardOperations.get().get(operationId);
  936. // Simulate copy progress
  937. const steps = ['copying_swimlanes', 'copying_lists', 'copying_cards', 'copying_attachments', 'finalizing'];
  938. for (let i = 0; i < steps.length; i++) {
  939. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  940. this.updateBoardOperation(operationId, operation);
  941. // Simulate work
  942. await new Promise(resolve => setTimeout(resolve, 1000));
  943. }
  944. }
  945. /**
  946. * Move board operation
  947. */
  948. async moveBoard(operationId, data) {
  949. const { sourceBoardId, targetBoardId, moveOptions } = data;
  950. const operation = boardOperations.get().get(operationId);
  951. // Simulate move progress
  952. const steps = ['preparing_move', 'moving_swimlanes', 'moving_lists', 'moving_cards', 'updating_references', 'finalizing'];
  953. for (let i = 0; i < steps.length; i++) {
  954. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  955. this.updateBoardOperation(operationId, operation);
  956. // Simulate work
  957. await new Promise(resolve => setTimeout(resolve, 800));
  958. }
  959. }
  960. /**
  961. * Copy swimlane operation
  962. */
  963. async copySwimlane(operationId, data) {
  964. const { sourceSwimlaneId, targetBoardId, copyOptions } = data;
  965. const operation = boardOperations.get().get(operationId);
  966. // Simulate copy progress
  967. const steps = ['copying_swimlane', 'copying_lists', 'copying_cards', 'finalizing'];
  968. for (let i = 0; i < steps.length; i++) {
  969. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  970. this.updateBoardOperation(operationId, operation);
  971. // Simulate work
  972. await new Promise(resolve => setTimeout(resolve, 500));
  973. }
  974. }
  975. /**
  976. * Move swimlane operation
  977. */
  978. async moveSwimlane(operationId, data) {
  979. const { sourceSwimlaneId, targetBoardId, moveOptions } = data;
  980. const operation = boardOperations.get().get(operationId);
  981. // Simulate move progress
  982. const steps = ['preparing_move', 'moving_swimlane', 'updating_references', 'finalizing'];
  983. for (let i = 0; i < steps.length; i++) {
  984. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  985. this.updateBoardOperation(operationId, operation);
  986. // Simulate work
  987. await new Promise(resolve => setTimeout(resolve, 400));
  988. }
  989. }
  990. /**
  991. * Copy list operation
  992. */
  993. async copyList(operationId, data) {
  994. const { sourceListId, targetBoardId, copyOptions } = data;
  995. const operation = boardOperations.get().get(operationId);
  996. // Simulate copy progress
  997. const steps = ['copying_list', 'copying_cards', 'copying_attachments', 'finalizing'];
  998. for (let i = 0; i < steps.length; i++) {
  999. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1000. this.updateBoardOperation(operationId, operation);
  1001. // Simulate work
  1002. await new Promise(resolve => setTimeout(resolve, 300));
  1003. }
  1004. }
  1005. /**
  1006. * Move list operation
  1007. */
  1008. async moveList(operationId, data) {
  1009. const { sourceListId, targetBoardId, moveOptions } = data;
  1010. const operation = boardOperations.get().get(operationId);
  1011. // Simulate move progress
  1012. const steps = ['preparing_move', 'moving_list', 'updating_references', 'finalizing'];
  1013. for (let i = 0; i < steps.length; i++) {
  1014. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1015. this.updateBoardOperation(operationId, operation);
  1016. // Simulate work
  1017. await new Promise(resolve => setTimeout(resolve, 200));
  1018. }
  1019. }
  1020. /**
  1021. * Copy card operation
  1022. */
  1023. async copyCard(operationId, data) {
  1024. const { sourceCardId, targetListId, copyOptions } = data;
  1025. const operation = boardOperations.get().get(operationId);
  1026. // Simulate copy progress
  1027. const steps = ['copying_card', 'copying_attachments', 'copying_checklists', 'finalizing'];
  1028. for (let i = 0; i < steps.length; i++) {
  1029. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1030. this.updateBoardOperation(operationId, operation);
  1031. // Simulate work
  1032. await new Promise(resolve => setTimeout(resolve, 150));
  1033. }
  1034. }
  1035. /**
  1036. * Move card operation
  1037. */
  1038. async moveCard(operationId, data) {
  1039. const { sourceCardId, targetListId, moveOptions } = data;
  1040. const operation = boardOperations.get().get(operationId);
  1041. // Simulate move progress
  1042. const steps = ['preparing_move', 'moving_card', 'updating_references', 'finalizing'];
  1043. for (let i = 0; i < steps.length; i++) {
  1044. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1045. this.updateBoardOperation(operationId, operation);
  1046. // Simulate work
  1047. await new Promise(resolve => setTimeout(resolve, 100));
  1048. }
  1049. }
  1050. /**
  1051. * Copy checklist operation
  1052. */
  1053. async copyChecklist(operationId, data) {
  1054. const { sourceChecklistId, targetCardId, copyOptions } = data;
  1055. const operation = boardOperations.get().get(operationId);
  1056. // Simulate copy progress
  1057. const steps = ['copying_checklist', 'copying_items', 'finalizing'];
  1058. for (let i = 0; i < steps.length; i++) {
  1059. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1060. this.updateBoardOperation(operationId, operation);
  1061. // Simulate work
  1062. await new Promise(resolve => setTimeout(resolve, 100));
  1063. }
  1064. }
  1065. /**
  1066. * Move checklist operation
  1067. */
  1068. async moveChecklist(operationId, data) {
  1069. const { sourceChecklistId, targetCardId, moveOptions } = data;
  1070. const operation = boardOperations.get().get(operationId);
  1071. // Simulate move progress
  1072. const steps = ['preparing_move', 'moving_checklist', 'finalizing'];
  1073. for (let i = 0; i < steps.length; i++) {
  1074. operation.progress = Math.round(((i + 1) / steps.length) * 100);
  1075. this.updateBoardOperation(operationId, operation);
  1076. // Simulate work
  1077. await new Promise(resolve => setTimeout(resolve, 50));
  1078. }
  1079. }
  1080. /**
  1081. * Get board operations for a specific board
  1082. */
  1083. getBoardOperations(boardId) {
  1084. const operations = boardOperations.get();
  1085. const boardOps = [];
  1086. for (const [operationId, operation] of operations) {
  1087. if (operation.boardId === boardId) {
  1088. boardOps.push(operation);
  1089. }
  1090. }
  1091. return boardOps.sort((a, b) => b.startTime - a.startTime);
  1092. }
  1093. /**
  1094. * Get all board operations with pagination
  1095. */
  1096. getAllBoardOperations(page = 1, limit = 20, searchTerm = '') {
  1097. const operations = boardOperations.get();
  1098. const allOps = Array.from(operations.values());
  1099. // Filter by search term if provided
  1100. let filteredOps = allOps;
  1101. if (searchTerm) {
  1102. filteredOps = allOps.filter(op =>
  1103. op.boardId.toLowerCase().includes(searchTerm.toLowerCase()) ||
  1104. op.type.toLowerCase().includes(searchTerm.toLowerCase())
  1105. );
  1106. }
  1107. // Sort by start time (newest first)
  1108. filteredOps.sort((a, b) => b.startTime - a.startTime);
  1109. // Paginate
  1110. const startIndex = (page - 1) * limit;
  1111. const endIndex = startIndex + limit;
  1112. const paginatedOps = filteredOps.slice(startIndex, endIndex);
  1113. return {
  1114. operations: paginatedOps,
  1115. total: filteredOps.length,
  1116. page: page,
  1117. limit: limit,
  1118. totalPages: Math.ceil(filteredOps.length / limit)
  1119. };
  1120. }
  1121. /**
  1122. * Get board operation statistics
  1123. */
  1124. getBoardOperationStats() {
  1125. const operations = boardOperations.get();
  1126. const stats = {
  1127. total: operations.size,
  1128. running: 0,
  1129. completed: 0,
  1130. error: 0,
  1131. byType: {}
  1132. };
  1133. for (const [operationId, operation] of operations) {
  1134. stats[operation.status]++;
  1135. if (!stats.byType[operation.type]) {
  1136. stats.byType[operation.type] = 0;
  1137. }
  1138. stats.byType[operation.type]++;
  1139. }
  1140. return stats;
  1141. }
  1142. }
  1143. // Export singleton instance
  1144. export const cronMigrationManager = new CronMigrationManager();
  1145. // Initialize cron jobs on server start
  1146. Meteor.startup(() => {
  1147. cronMigrationManager.initializeCronJobs();
  1148. });
  1149. // Meteor methods for client-server communication
  1150. Meteor.methods({
  1151. 'cron.startAllMigrations'() {
  1152. if (!this.userId) {
  1153. throw new Meteor.Error('not-authorized');
  1154. }
  1155. return cronMigrationManager.startAllMigrations();
  1156. },
  1157. 'cron.startJob'(cronName) {
  1158. if (!this.userId) {
  1159. throw new Meteor.Error('not-authorized');
  1160. }
  1161. return cronMigrationManager.startCronJob(cronName);
  1162. },
  1163. 'cron.stopJob'(cronName) {
  1164. if (!this.userId) {
  1165. throw new Meteor.Error('not-authorized');
  1166. }
  1167. return cronMigrationManager.stopCronJob(cronName);
  1168. },
  1169. 'cron.pauseJob'(cronName) {
  1170. if (!this.userId) {
  1171. throw new Meteor.Error('not-authorized');
  1172. }
  1173. return cronMigrationManager.pauseCronJob(cronName);
  1174. },
  1175. 'cron.resumeJob'(cronName) {
  1176. if (!this.userId) {
  1177. throw new Meteor.Error('not-authorized');
  1178. }
  1179. return cronMigrationManager.resumeCronJob(cronName);
  1180. },
  1181. 'cron.removeJob'(cronName) {
  1182. if (!this.userId) {
  1183. throw new Meteor.Error('not-authorized');
  1184. }
  1185. return cronMigrationManager.removeCronJob(cronName);
  1186. },
  1187. 'cron.addJob'(jobData) {
  1188. if (!this.userId) {
  1189. throw new Meteor.Error('not-authorized');
  1190. }
  1191. return cronMigrationManager.addCronJob(jobData);
  1192. },
  1193. 'cron.getJobs'() {
  1194. return cronMigrationManager.getAllCronJobs();
  1195. },
  1196. 'cron.getMigrationProgress'() {
  1197. return {
  1198. progress: cronMigrationProgress.get(),
  1199. status: cronMigrationStatus.get(),
  1200. currentStep: cronMigrationCurrentStep.get(),
  1201. steps: cronMigrationSteps.get(),
  1202. isMigrating: cronIsMigrating.get()
  1203. };
  1204. },
  1205. 'cron.startBoardOperation'(boardId, operationType, operationData) {
  1206. if (!this.userId) {
  1207. throw new Meteor.Error('not-authorized');
  1208. }
  1209. return cronMigrationManager.startBoardOperation(boardId, operationType, operationData);
  1210. },
  1211. 'cron.getBoardOperations'(boardId) {
  1212. if (!this.userId) {
  1213. throw new Meteor.Error('not-authorized');
  1214. }
  1215. return cronMigrationManager.getBoardOperations(boardId);
  1216. },
  1217. 'cron.getAllBoardOperations'(page, limit, searchTerm) {
  1218. if (!this.userId) {
  1219. throw new Meteor.Error('not-authorized');
  1220. }
  1221. return cronMigrationManager.getAllBoardOperations(page, limit, searchTerm);
  1222. },
  1223. 'cron.getBoardOperationStats'() {
  1224. if (!this.userId) {
  1225. throw new Meteor.Error('not-authorized');
  1226. }
  1227. return cronMigrationManager.getBoardOperationStats();
  1228. },
  1229. 'cron.getJobDetails'(jobId) {
  1230. if (!this.userId) {
  1231. throw new Meteor.Error('not-authorized');
  1232. }
  1233. return cronJobStorage.getJobDetails(jobId);
  1234. },
  1235. 'cron.getQueueStats'() {
  1236. if (!this.userId) {
  1237. throw new Meteor.Error('not-authorized');
  1238. }
  1239. return cronJobStorage.getQueueStats();
  1240. },
  1241. 'cron.getSystemResources'() {
  1242. if (!this.userId) {
  1243. throw new Meteor.Error('not-authorized');
  1244. }
  1245. return cronJobStorage.getSystemResources();
  1246. },
  1247. 'cron.pauseJob'(jobId) {
  1248. if (!this.userId) {
  1249. throw new Meteor.Error('not-authorized');
  1250. }
  1251. cronJobStorage.updateQueueStatus(jobId, 'paused');
  1252. cronJobStorage.saveJobStatus(jobId, { status: 'paused' });
  1253. return { success: true };
  1254. },
  1255. 'cron.resumeJob'(jobId) {
  1256. if (!this.userId) {
  1257. throw new Meteor.Error('not-authorized');
  1258. }
  1259. cronJobStorage.updateQueueStatus(jobId, 'pending');
  1260. cronJobStorage.saveJobStatus(jobId, { status: 'pending' });
  1261. return { success: true };
  1262. },
  1263. 'cron.stopJob'(jobId) {
  1264. if (!this.userId) {
  1265. throw new Meteor.Error('not-authorized');
  1266. }
  1267. cronJobStorage.updateQueueStatus(jobId, 'stopped');
  1268. cronJobStorage.saveJobStatus(jobId, {
  1269. status: 'stopped',
  1270. stoppedAt: new Date()
  1271. });
  1272. return { success: true };
  1273. },
  1274. 'cron.cleanupOldJobs'(daysOld) {
  1275. if (!this.userId) {
  1276. throw new Meteor.Error('not-authorized');
  1277. }
  1278. return cronJobStorage.cleanupOldJobs(daysOld);
  1279. },
  1280. 'cron.getBoardMigrationStats'() {
  1281. if (!this.userId) {
  1282. throw new Meteor.Error('not-authorized');
  1283. }
  1284. // Import the board migration detector
  1285. const { boardMigrationDetector } = require('./boardMigrationDetector');
  1286. return boardMigrationDetector.getMigrationStats();
  1287. },
  1288. 'cron.forceBoardMigrationScan'() {
  1289. if (!this.userId) {
  1290. throw new Meteor.Error('not-authorized');
  1291. }
  1292. // Import the board migration detector
  1293. const { boardMigrationDetector } = require('./boardMigrationDetector');
  1294. return boardMigrationDetector.forceScan();
  1295. }
  1296. });