MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / check

Function check

packages/db/src/clickhouse/migration.ts:466–512  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 5

formatMemoryFunction · 0.85
queryMethod · 0.80
formatNumberFunction · 0.70
thenMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected