@514labs/moose-lib 0.6.267-ci-2-g3cd14684 → 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.
@@ -962,8 +962,15 @@ var runApis = async (config) => {
962
962
  const apisCluster = new Cluster({
963
963
  maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
964
964
  workerStart: async () => {
965
+ const workerInfo = `[Worker ${process.pid}]`;
966
+ const startTime = Date.now();
967
+ console.log(`${workerInfo} workerStart: beginning initialization`);
965
968
  let temporalClient;
966
969
  if (config.temporalConfig) {
970
+ const temporalStart = Date.now();
971
+ console.log(
972
+ `${workerInfo} workerStart: initializing Temporal client...`
973
+ );
967
974
  temporalClient = await getTemporalClient(
968
975
  config.temporalConfig.url,
969
976
  config.temporalConfig.namespace,
@@ -971,29 +978,51 @@ var runApis = async (config) => {
971
978
  config.temporalConfig.clientKey,
972
979
  config.temporalConfig.apiKey
973
980
  );
981
+ console.log(
982
+ `${workerInfo} workerStart: Temporal client initialized in ${Date.now() - temporalStart}ms`
983
+ );
974
984
  }
985
+ const clickhouseStart = Date.now();
986
+ console.log(
987
+ `${workerInfo} workerStart: initializing ClickHouse client...`
988
+ );
975
989
  const clickhouseClient = getClickhouseClient(
976
990
  toClientConfig(config.clickhouseConfig)
977
991
  );
992
+ console.log(
993
+ `${workerInfo} workerStart: ClickHouse client initialized in ${Date.now() - clickhouseStart}ms`
994
+ );
978
995
  let publicKey;
979
996
  if (config.jwtConfig?.secret) {
980
- console.log("Importing JWT public key...");
997
+ const jwtStart = Date.now();
998
+ console.log(`${workerInfo} workerStart: importing JWT public key...`);
981
999
  publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
1000
+ console.log(
1001
+ `${workerInfo} workerStart: JWT key imported in ${Date.now() - jwtStart}ms`
1002
+ );
982
1003
  }
983
- const server = http2.createServer(
984
- await createMainRouter(
985
- publicKey,
986
- clickhouseClient,
987
- temporalClient,
988
- config.apisDir,
989
- config.enforceAuth,
990
- config.isDmv2,
991
- config.jwtConfig
992
- )
1004
+ const routerStart = Date.now();
1005
+ console.log(`${workerInfo} workerStart: creating main router...`);
1006
+ const router = await createMainRouter(
1007
+ publicKey,
1008
+ clickhouseClient,
1009
+ temporalClient,
1010
+ config.apisDir,
1011
+ config.enforceAuth,
1012
+ config.isDmv2,
1013
+ config.jwtConfig
1014
+ );
1015
+ console.log(
1016
+ `${workerInfo} workerStart: main router created in ${Date.now() - routerStart}ms`
993
1017
  );
1018
+ const serverStart = Date.now();
1019
+ console.log(`${workerInfo} workerStart: creating HTTP server...`);
1020
+ const server = http2.createServer(router);
994
1021
  const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
995
1022
  server.listen(port, "localhost", () => {
996
- console.log(`Server running on port ${port}`);
1023
+ console.log(
1024
+ `${workerInfo} Server running on port ${port} (total startup: ${Date.now() - startTime}ms)`
1025
+ );
997
1026
  });
998
1027
  return server;
999
1028
  },
@@ -1614,43 +1643,106 @@ if (getMooseInternal() === void 0) {
1614
1643
  globalThis.moose_internal = moose_internal;
1615
1644
  }
1616
1645
  var dumpMooseInternal = async () => {
1617
- loadIndex();
1646
+ await loadIndex();
1618
1647
  console.log(
1619
1648
  "___MOOSE_STUFF___start",
1620
1649
  JSON.stringify(toInfraMap(getMooseInternal())),
1621
1650
  "end___MOOSE_STUFF___"
1622
1651
  );
1623
1652
  };
1624
- var loadIndex = () => {
1625
- const registry = getMooseInternal();
1626
- registry.tables.clear();
1627
- registry.streams.clear();
1628
- registry.ingestApis.clear();
1629
- registry.apis.clear();
1630
- registry.sqlResources.clear();
1631
- registry.workflows.clear();
1632
- registry.webApps.clear();
1633
- const appDir = `${process2.cwd()}/${getSourceDir()}`;
1634
- Object.keys(__require.cache).forEach((key) => {
1635
- if (key.startsWith(appDir)) {
1636
- delete __require.cache[key];
1637
- }
1638
- });
1639
- try {
1640
- __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1641
- } catch (error) {
1642
- let hint;
1643
- const details = error instanceof Error ? error.message : String(error);
1644
- if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1645
- hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
1646
- }
1647
- const errorMsg = `${hint ?? ""}${details}`;
1648
- const cause = error instanceof Error ? error : void 0;
1649
- throw new Error(errorMsg, { cause });
1653
+ var indexLoadState = "unloaded";
1654
+ var indexLoadPromise = null;
1655
+ var loadIndex = async () => {
1656
+ const workerInfo = `[Worker ${process2.pid}]`;
1657
+ if (indexLoadState === "loaded") {
1658
+ console.log(
1659
+ `${workerInfo} loadIndex: already loaded, returning immediately`
1660
+ );
1661
+ return;
1662
+ }
1663
+ if (indexLoadState === "loading" && indexLoadPromise) {
1664
+ console.log(
1665
+ `${workerInfo} loadIndex: already loading, waiting for completion`
1666
+ );
1667
+ return indexLoadPromise;
1650
1668
  }
1669
+ console.log(`${workerInfo} loadIndex: starting load process`);
1670
+ const startTime = Date.now();
1671
+ const delay = Math.random() * 500;
1672
+ console.log(
1673
+ `${workerInfo} loadIndex: waiting ${delay.toFixed(0)}ms to stagger load`
1674
+ );
1675
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
1676
+ if (indexLoadState === "loading" && indexLoadPromise) {
1677
+ console.log(
1678
+ `${workerInfo} loadIndex: another worker started loading during delay, waiting`
1679
+ );
1680
+ return indexLoadPromise;
1681
+ }
1682
+ if (indexLoadState === "loaded") {
1683
+ console.log(
1684
+ `${workerInfo} loadIndex: loaded by another worker during delay`
1685
+ );
1686
+ return;
1687
+ }
1688
+ indexLoadState = "loading";
1689
+ indexLoadPromise = (async () => {
1690
+ try {
1691
+ console.log(`${workerInfo} loadIndex: clearing registry...`);
1692
+ const clearStart = Date.now();
1693
+ const registry = getMooseInternal();
1694
+ registry.tables.clear();
1695
+ registry.streams.clear();
1696
+ registry.ingestApis.clear();
1697
+ registry.apis.clear();
1698
+ registry.sqlResources.clear();
1699
+ registry.workflows.clear();
1700
+ registry.webApps.clear();
1701
+ console.log(
1702
+ `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
1703
+ );
1704
+ console.log(`${workerInfo} loadIndex: clearing require cache...`);
1705
+ const cacheStart = Date.now();
1706
+ const appDir = `${process2.cwd()}/${getSourceDir()}`;
1707
+ Object.keys(__require.cache).forEach((key) => {
1708
+ if (key.startsWith(appDir)) {
1709
+ delete __require.cache[key];
1710
+ }
1711
+ });
1712
+ console.log(
1713
+ `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1714
+ );
1715
+ console.log(`${workerInfo} loadIndex: requiring index.ts...`);
1716
+ const requireStart = Date.now();
1717
+ __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1718
+ console.log(
1719
+ `${workerInfo} loadIndex: require completed in ${Date.now() - requireStart}ms`
1720
+ );
1721
+ indexLoadState = "loaded";
1722
+ console.log(
1723
+ `${workerInfo} loadIndex: total load time ${Date.now() - startTime}ms`
1724
+ );
1725
+ } catch (error) {
1726
+ console.error(
1727
+ `${workerInfo} loadIndex: FAILED after ${Date.now() - startTime}ms`,
1728
+ error
1729
+ );
1730
+ indexLoadState = "unloaded";
1731
+ indexLoadPromise = null;
1732
+ let hint;
1733
+ const details = error instanceof Error ? error.message : String(error);
1734
+ if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1735
+ hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
1736
+ }
1737
+ const errorMsg = `${hint ?? ""}${details}`;
1738
+ const cause = error instanceof Error ? error : void 0;
1739
+ throw new Error(errorMsg, { cause });
1740
+ }
1741
+ })();
1742
+ return indexLoadPromise;
1651
1743
  };
1652
1744
  var getStreamingFunctions = async () => {
1653
- loadIndex();
1745
+ await loadIndex();
1654
1746
  const registry = getMooseInternal();
1655
1747
  const transformFunctions = /* @__PURE__ */ new Map();
1656
1748
  registry.streams.forEach((stream) => {
@@ -1677,7 +1769,7 @@ var getStreamingFunctions = async () => {
1677
1769
  return transformFunctions;
1678
1770
  };
1679
1771
  var getApis2 = async () => {
1680
- loadIndex();
1772
+ await loadIndex();
1681
1773
  const apiFunctions = /* @__PURE__ */ new Map();
1682
1774
  const registry = getMooseInternal();
1683
1775
  const versionCountByName = /* @__PURE__ */ new Map();
@@ -1709,7 +1801,7 @@ var getApis2 = async () => {
1709
1801
  return apiFunctions;
1710
1802
  };
1711
1803
  var getWorkflows2 = async () => {
1712
- loadIndex();
1804
+ await loadIndex();
1713
1805
  const registry = getMooseInternal();
1714
1806
  return registry.workflows;
1715
1807
  };
@@ -1743,7 +1835,7 @@ var getTaskForWorkflow = async (workflowName, taskName) => {
1743
1835
  return task;
1744
1836
  };
1745
1837
  var getWebApps2 = async () => {
1746
- loadIndex();
1838
+ await loadIndex();
1747
1839
  return getMooseInternal().webApps;
1748
1840
  };
1749
1841