()
| 464 | let checking = false; // Add flag to prevent multiple concurrent checks |
| 465 | |
| 466 | async function check() { |
| 467 | if (checking) return; // Skip if already checking |
| 468 | checking = true; |
| 469 | |
| 470 | try { |
| 471 | const res = await chMigrationClient |
| 472 | .query({ |
| 473 | query: `SELECT |
| 474 | query_id, |
| 475 | elapsed, |
| 476 | read_rows, |
| 477 | written_rows, |
| 478 | memory_usage |
| 479 | FROM system.processes |
| 480 | WHERE query_id = '${activeQueryId}'`, |
| 481 | format: 'JSONEachRow', |
| 482 | }) |
| 483 | .then((res) => res.json()); |
| 484 | |
| 485 | const formatMemory = (bytes: number) => { |
| 486 | const units = ['B', 'KB', 'MB', 'GB']; |
| 487 | let size = bytes; |
| 488 | let unitIndex = 0; |
| 489 | while (size >= 1024 && unitIndex < units.length - 1) { |
| 490 | size /= 1024; |
| 491 | unitIndex++; |
| 492 | } |
| 493 | return `${Math.round(size * 100) / 100}${units[unitIndex]}`; |
| 494 | }; |
| 495 | |
| 496 | const formatNumber = (num: number) => { |
| 497 | return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); |
| 498 | }; |
| 499 | |
| 500 | if (Array.isArray(res) && res.length > 0) { |
| 501 | const { elapsed, read_rows, written_rows, memory_usage } = |
| 502 | res[0] as any; |
| 503 | console.log( |
| 504 | `Progress: ${elapsed.toFixed(2)}s | Memory: ${formatMemory(memory_usage)} | Read: ${formatNumber(read_rows)} rows | Written: ${formatNumber(written_rows)} rows`, |
| 505 | ); |
| 506 | } |
| 507 | } finally { |
| 508 | checking = false; |
| 509 | } |
| 510 | |
| 511 | timer = setTimeout(check, 5000); // Schedule next check after current one completes |
| 512 | } |
| 513 | |
| 514 | // Start the first check after 5 seconds |
| 515 | timer = setTimeout(check, 5000); |
nothing calls this directly
no test coverage detected