@514labs/moose-lib 0.6.267-ci-5-gfe9b0c33 → 0.6.267-ci-7-g09e4deda

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.
@@ -606,7 +606,14 @@ var Cluster = class {
606
606
  */
607
607
  bootWorkers = async (numWorkers) => {
608
608
  console.info(`Setting ${numWorkers} workers...`);
609
+ const staggerDelay = process.env.NODE_ENV === "production" ? 2e3 : 0;
609
610
  for (let i = 0; i < numWorkers; i++) {
611
+ if (i > 0 && staggerDelay > 0) {
612
+ await new Promise((resolve2) => setTimeout(resolve2, staggerDelay));
613
+ console.info(
614
+ `Starting worker ${i + 1}/${numWorkers} (staggered ${staggerDelay}ms)`
615
+ );
616
+ }
610
617
  import_node_cluster.default.fork();
611
618
  }
612
619
  import_node_cluster.default.on("online", (worker) => {
@@ -972,6 +979,17 @@ var createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisD
972
979
  };
973
980
  };
974
981
  var runApis = async (config) => {
982
+ if (config.isDmv2) {
983
+ const preloadStart = Date.now();
984
+ console.log(
985
+ `[Primary ${process.pid}] Pre-loading index.ts before forking workers...`
986
+ );
987
+ await getApis2();
988
+ await getWebApps2();
989
+ console.log(
990
+ `[Primary ${process.pid}] Index pre-loaded in ${Date.now() - preloadStart}ms`
991
+ );
992
+ }
975
993
  const apisCluster = new Cluster({
976
994
  maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
977
995
  workerStart: async () => {
@@ -1714,17 +1732,23 @@ var loadIndex = async () => {
1714
1732
  console.log(
1715
1733
  `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
1716
1734
  );
1717
- console.log(`${workerInfo} loadIndex: clearing require cache...`);
1718
- const cacheStart = Date.now();
1719
- const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
1720
- Object.keys(require.cache).forEach((key) => {
1721
- if (key.startsWith(appDir)) {
1722
- delete require.cache[key];
1723
- }
1724
- });
1725
- console.log(
1726
- `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1727
- );
1735
+ if (import_process.default.env.NODE_ENV !== "production") {
1736
+ console.log(`${workerInfo} loadIndex: clearing require cache...`);
1737
+ const cacheStart = Date.now();
1738
+ const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
1739
+ Object.keys(require.cache).forEach((key) => {
1740
+ if (key.startsWith(appDir)) {
1741
+ delete require.cache[key];
1742
+ }
1743
+ });
1744
+ console.log(
1745
+ `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1746
+ );
1747
+ } else {
1748
+ console.log(
1749
+ `${workerInfo} loadIndex: skipping cache clear in production mode`
1750
+ );
1751
+ }
1728
1752
  console.log(`${workerInfo} loadIndex: requiring index.ts...`);
1729
1753
  const requireStart = Date.now();
1730
1754
  require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);