cronMigrationManager.js 42 KB

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