@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.
@@ -593,7 +593,14 @@ var Cluster = class {
593
593
  */
594
594
  bootWorkers = async (numWorkers) => {
595
595
  console.info(`Setting ${numWorkers} workers...`);
596
+ const staggerDelay = process.env.NODE_ENV === "production" ? 2e3 : 0;
596
597
  for (let i = 0; i < numWorkers; i++) {
598
+ if (i > 0 && staggerDelay > 0) {
599
+ await new Promise((resolve2) => setTimeout(resolve2, staggerDelay));
600
+ console.info(
601
+ `Starting worker ${i + 1}/${numWorkers} (staggered ${staggerDelay}ms)`
602
+ );
603
+ }
597
604
  cluster.fork();
598
605
  }
599
606
  cluster.on("online", (worker) => {
@@ -959,6 +966,17 @@ var createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisD
959
966
  };
960
967
  };
961
968
  var runApis = async (config) => {
969
+ if (config.isDmv2) {
970
+ const preloadStart = Date.now();
971
+ console.log(
972
+ `[Primary ${process.pid}] Pre-loading index.ts before forking workers...`
973
+ );
974
+ await getApis2();
975
+ await getWebApps2();
976
+ console.log(
977
+ `[Primary ${process.pid}] Index pre-loaded in ${Date.now() - preloadStart}ms`
978
+ );
979
+ }
962
980
  const apisCluster = new Cluster({
963
981
  maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
964
982
  workerStart: async () => {
@@ -1701,17 +1719,23 @@ var loadIndex = async () => {
1701
1719
  console.log(
1702
1720
  `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
1703
1721
  );
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
- );
1722
+ if (process2.env.NODE_ENV !== "production") {
1723
+ console.log(`${workerInfo} loadIndex: clearing require cache...`);
1724
+ const cacheStart = Date.now();
1725
+ const appDir = `${process2.cwd()}/${getSourceDir()}`;
1726
+ Object.keys(__require.cache).forEach((key) => {
1727
+ if (key.startsWith(appDir)) {
1728
+ delete __require.cache[key];
1729
+ }
1730
+ });
1731
+ console.log(
1732
+ `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1733
+ );
1734
+ } else {
1735
+ console.log(
1736
+ `${workerInfo} loadIndex: skipping cache clear in production mode`
1737
+ );
1738
+ }
1715
1739
  console.log(`${workerInfo} loadIndex: requiring index.ts...`);
1716
1740
  const requireStart = Date.now();
1717
1741
  __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);