@514labs/moose-lib 0.6.267-ci-2-g580f80e4 → 0.6.267-ci-3-g2d546d7e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -975,8 +975,15 @@ var runApis = async (config) => {
975
975
  const apisCluster = new Cluster({
976
976
  maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
977
977
  workerStart: async () => {
978
+ const workerInfo = `[Worker ${process.pid}]`;
979
+ const startTime = Date.now();
980
+ console.log(`${workerInfo} workerStart: beginning initialization`);
978
981
  let temporalClient;
979
982
  if (config.temporalConfig) {
983
+ const temporalStart = Date.now();
984
+ console.log(
985
+ `${workerInfo} workerStart: initializing Temporal client...`
986
+ );
980
987
  temporalClient = await getTemporalClient(
981
988
  config.temporalConfig.url,
982
989
  config.temporalConfig.namespace,
@@ -984,29 +991,51 @@ var runApis = async (config) => {
984
991
  config.temporalConfig.clientKey,
985
992
  config.temporalConfig.apiKey
986
993
  );
994
+ console.log(
995
+ `${workerInfo} workerStart: Temporal client initialized in ${Date.now() - temporalStart}ms`
996
+ );
987
997
  }
998
+ const clickhouseStart = Date.now();
999
+ console.log(
1000
+ `${workerInfo} workerStart: initializing ClickHouse client...`
1001
+ );
988
1002
  const clickhouseClient = getClickhouseClient(
989
1003
  toClientConfig(config.clickhouseConfig)
990
1004
  );
1005
+ console.log(
1006
+ `${workerInfo} workerStart: ClickHouse client initialized in ${Date.now() - clickhouseStart}ms`
1007
+ );
991
1008
  let publicKey;
992
1009
  if (config.jwtConfig?.secret) {
993
- console.log("Importing JWT public key...");
1010
+ const jwtStart = Date.now();
1011
+ console.log(`${workerInfo} workerStart: importing JWT public key...`);
994
1012
  publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
1013
+ console.log(
1014
+ `${workerInfo} workerStart: JWT key imported in ${Date.now() - jwtStart}ms`
1015
+ );
995
1016
  }
996
- const server = import_http2.default.createServer(
997
- await createMainRouter(
998
- publicKey,
999
- clickhouseClient,
1000
- temporalClient,
1001
- config.apisDir,
1002
- config.enforceAuth,
1003
- config.isDmv2,
1004
- config.jwtConfig
1005
- )
1017
+ const routerStart = Date.now();
1018
+ console.log(`${workerInfo} workerStart: creating main router...`);
1019
+ const router = await createMainRouter(
1020
+ publicKey,
1021
+ clickhouseClient,
1022
+ temporalClient,
1023
+ config.apisDir,
1024
+ config.enforceAuth,
1025
+ config.isDmv2,
1026
+ config.jwtConfig
1027
+ );
1028
+ console.log(
1029
+ `${workerInfo} workerStart: main router created in ${Date.now() - routerStart}ms`
1006
1030
  );
1031
+ const serverStart = Date.now();
1032
+ console.log(`${workerInfo} workerStart: creating HTTP server...`);
1033
+ const server = import_http2.default.createServer(router);
1007
1034
  const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
1008
1035
  server.listen(port, "localhost", () => {
1009
- console.log(`Server running on port ${port}`);
1036
+ console.log(
1037
+ `${workerInfo} Server running on port ${port} (total startup: ${Date.now() - startTime}ms)`
1038
+ );
1010
1039
  });
1011
1040
  return server;
1012
1041
  },
@@ -1637,15 +1666,43 @@ var dumpMooseInternal = async () => {
1637
1666
  var indexLoadState = "unloaded";
1638
1667
  var indexLoadPromise = null;
1639
1668
  var loadIndex = async () => {
1669
+ const workerInfo = `[Worker ${import_process.default.pid}]`;
1640
1670
  if (indexLoadState === "loaded") {
1671
+ console.log(
1672
+ `${workerInfo} loadIndex: already loaded, returning immediately`
1673
+ );
1641
1674
  return;
1642
1675
  }
1643
1676
  if (indexLoadState === "loading" && indexLoadPromise) {
1677
+ console.log(
1678
+ `${workerInfo} loadIndex: already loading, waiting for completion`
1679
+ );
1680
+ return indexLoadPromise;
1681
+ }
1682
+ console.log(`${workerInfo} loadIndex: starting load process`);
1683
+ const startTime = Date.now();
1684
+ const delay = Math.random() * 500;
1685
+ console.log(
1686
+ `${workerInfo} loadIndex: waiting ${delay.toFixed(0)}ms to stagger load`
1687
+ );
1688
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
1689
+ if (indexLoadState === "loading" && indexLoadPromise) {
1690
+ console.log(
1691
+ `${workerInfo} loadIndex: another worker started loading during delay, waiting`
1692
+ );
1644
1693
  return indexLoadPromise;
1645
1694
  }
1695
+ if (indexLoadState === "loaded") {
1696
+ console.log(
1697
+ `${workerInfo} loadIndex: loaded by another worker during delay`
1698
+ );
1699
+ return;
1700
+ }
1646
1701
  indexLoadState = "loading";
1647
1702
  indexLoadPromise = (async () => {
1648
1703
  try {
1704
+ console.log(`${workerInfo} loadIndex: clearing registry...`);
1705
+ const clearStart = Date.now();
1649
1706
  const registry = getMooseInternal();
1650
1707
  registry.tables.clear();
1651
1708
  registry.streams.clear();
@@ -1654,15 +1711,35 @@ var loadIndex = async () => {
1654
1711
  registry.sqlResources.clear();
1655
1712
  registry.workflows.clear();
1656
1713
  registry.webApps.clear();
1714
+ console.log(
1715
+ `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
1716
+ );
1717
+ console.log(`${workerInfo} loadIndex: clearing require cache...`);
1718
+ const cacheStart = Date.now();
1657
1719
  const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
1658
1720
  Object.keys(require.cache).forEach((key) => {
1659
1721
  if (key.startsWith(appDir)) {
1660
1722
  delete require.cache[key];
1661
1723
  }
1662
1724
  });
1725
+ console.log(
1726
+ `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1727
+ );
1728
+ console.log(`${workerInfo} loadIndex: requiring index.ts...`);
1729
+ const requireStart = Date.now();
1663
1730
  require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);
1731
+ console.log(
1732
+ `${workerInfo} loadIndex: require completed in ${Date.now() - requireStart}ms`
1733
+ );
1664
1734
  indexLoadState = "loaded";
1735
+ console.log(
1736
+ `${workerInfo} loadIndex: total load time ${Date.now() - startTime}ms`
1737
+ );
1665
1738
  } catch (error) {
1739
+ console.error(
1740
+ `${workerInfo} loadIndex: FAILED after ${Date.now() - startTime}ms`,
1741
+ error
1742
+ );
1666
1743
  indexLoadState = "unloaded";
1667
1744
  indexLoadPromise = null;
1668
1745
  let hint;