@514labs/moose-lib 0.6.267-ci-2-g580f80e4 → 0.6.267-ci-5-gfe9b0c33

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.
package/dist/index.js CHANGED
@@ -806,15 +806,43 @@ if (getMooseInternal() === void 0) {
806
806
  var indexLoadState = "unloaded";
807
807
  var indexLoadPromise = null;
808
808
  var loadIndex = async () => {
809
+ const workerInfo = `[Worker ${import_process.default.pid}]`;
809
810
  if (indexLoadState === "loaded") {
811
+ console.log(
812
+ `${workerInfo} loadIndex: already loaded, returning immediately`
813
+ );
810
814
  return;
811
815
  }
812
816
  if (indexLoadState === "loading" && indexLoadPromise) {
817
+ console.log(
818
+ `${workerInfo} loadIndex: already loading, waiting for completion`
819
+ );
813
820
  return indexLoadPromise;
814
821
  }
822
+ console.log(`${workerInfo} loadIndex: starting load process`);
823
+ const startTime = Date.now();
824
+ const delay = Math.random() * 500;
825
+ console.log(
826
+ `${workerInfo} loadIndex: waiting ${delay.toFixed(0)}ms to stagger load`
827
+ );
828
+ await new Promise((resolve) => setTimeout(resolve, delay));
829
+ if (indexLoadState === "loading" && indexLoadPromise) {
830
+ console.log(
831
+ `${workerInfo} loadIndex: another worker started loading during delay, waiting`
832
+ );
833
+ return indexLoadPromise;
834
+ }
835
+ if (indexLoadState === "loaded") {
836
+ console.log(
837
+ `${workerInfo} loadIndex: loaded by another worker during delay`
838
+ );
839
+ return;
840
+ }
815
841
  indexLoadState = "loading";
816
842
  indexLoadPromise = (async () => {
817
843
  try {
844
+ console.log(`${workerInfo} loadIndex: clearing registry...`);
845
+ const clearStart = Date.now();
818
846
  const registry = getMooseInternal();
819
847
  registry.tables.clear();
820
848
  registry.streams.clear();
@@ -823,15 +851,35 @@ var loadIndex = async () => {
823
851
  registry.sqlResources.clear();
824
852
  registry.workflows.clear();
825
853
  registry.webApps.clear();
854
+ console.log(
855
+ `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
856
+ );
857
+ console.log(`${workerInfo} loadIndex: clearing require cache...`);
858
+ const cacheStart = Date.now();
826
859
  const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
827
860
  Object.keys(require.cache).forEach((key) => {
828
861
  if (key.startsWith(appDir)) {
829
862
  delete require.cache[key];
830
863
  }
831
864
  });
865
+ console.log(
866
+ `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
867
+ );
868
+ console.log(`${workerInfo} loadIndex: requiring index.ts...`);
869
+ const requireStart = Date.now();
832
870
  require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);
871
+ console.log(
872
+ `${workerInfo} loadIndex: require completed in ${Date.now() - requireStart}ms`
873
+ );
833
874
  indexLoadState = "loaded";
875
+ console.log(
876
+ `${workerInfo} loadIndex: total load time ${Date.now() - startTime}ms`
877
+ );
834
878
  } catch (error) {
879
+ console.error(
880
+ `${workerInfo} loadIndex: FAILED after ${Date.now() - startTime}ms`,
881
+ error
882
+ );
835
883
  indexLoadState = "unloaded";
836
884
  indexLoadPromise = null;
837
885
  let hint;