construct-hub 0.4.303 → 0.4.304

Sign up to get free protection for your applications and to get access to all the features.
@@ -2111,10 +2111,10 @@ var require_local_reservoir = __commonJS({
2111
2111
  }
2112
2112
  };
2113
2113
  LocalReservoir.prototype.isSampled = function isSampled() {
2114
- var now = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
2115
- if (now !== this.thisSecond) {
2114
+ var now2 = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
2115
+ if (now2 !== this.thisSecond) {
2116
2116
  this.usedThisSecond = 0;
2117
- this.thisSecond = now;
2117
+ this.thisSecond = now2;
2118
2118
  }
2119
2119
  if (this.usedThisSecond >= this.fixedTarget) {
2120
2120
  return Math.random() < this.fallbackRate;
@@ -2288,9 +2288,9 @@ var require_reservoir = __commonJS({
2288
2288
  this.reportInterval = 1;
2289
2289
  this.reportElapsed = 0;
2290
2290
  };
2291
- Reservoir.prototype.borrowOrTake = function borrowOrTake(now, canBorrow) {
2292
- this.adjustThisSec(now);
2293
- if (this.quota >= 0 && this.TTL >= now) {
2291
+ Reservoir.prototype.borrowOrTake = function borrowOrTake(now2, canBorrow) {
2292
+ this.adjustThisSec(now2);
2293
+ if (this.quota >= 0 && this.TTL >= now2) {
2294
2294
  if (this.takenThisSec >= this.quota) {
2295
2295
  return false;
2296
2296
  }
@@ -2305,11 +2305,11 @@ var require_reservoir = __commonJS({
2305
2305
  return "borrow";
2306
2306
  }
2307
2307
  };
2308
- Reservoir.prototype.adjustThisSec = function adjustThisSec(now) {
2309
- if (now !== this.thisSec) {
2308
+ Reservoir.prototype.adjustThisSec = function adjustThisSec(now2) {
2309
+ if (now2 !== this.thisSec) {
2310
2310
  this.takenThisSec = 0;
2311
2311
  this.borrowedThisSec = 0;
2312
- this.thisSec = now;
2312
+ this.thisSec = now2;
2313
2313
  }
2314
2314
  };
2315
2315
  Reservoir.prototype.loadNewQuota = function loadNewQuota(quota, TTL, interval) {
@@ -2518,7 +2518,7 @@ var require_service_connector = __commonJS({
2518
2518
  };
2519
2519
  var constructStatisticsDocs = function constructStatisticsDocs2(rules) {
2520
2520
  var documents = [];
2521
- var now = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2521
+ var now2 = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2522
2522
  rules.forEach(function(rule) {
2523
2523
  var statistics = rule.snapshotStatistics();
2524
2524
  var doc = {
@@ -2527,7 +2527,7 @@ var require_service_connector = __commonJS({
2527
2527
  "RequestCount": statistics.requestCount,
2528
2528
  "BorrowCount": statistics.borrowCount,
2529
2529
  "SampledCount": statistics.sampledCount,
2530
- "Timestamp": now
2530
+ "Timestamp": now2
2531
2531
  };
2532
2532
  documents.push(doc);
2533
2533
  });
@@ -2598,8 +2598,8 @@ var require_rule_cache = __commonJS({
2598
2598
  * @module RuleCache
2599
2599
  * @function getMatchedRule
2600
2600
  */
2601
- getMatchedRule: function getMatchedRule(sampleRequest, now) {
2602
- if (isExpired(now)) {
2601
+ getMatchedRule: function getMatchedRule(sampleRequest, now2) {
2602
+ if (isExpired(now2)) {
2603
2603
  return null;
2604
2604
  }
2605
2605
  var matchedRule;
@@ -2661,18 +2661,18 @@ var require_rule_cache = __commonJS({
2661
2661
  getRules: function getRules() {
2662
2662
  return this.rules;
2663
2663
  },
2664
- timestamp: function timestamp(now) {
2665
- this.lastUpdated = now;
2664
+ timestamp: function timestamp(now2) {
2665
+ this.lastUpdated = now2;
2666
2666
  },
2667
2667
  getLastUpdated: function getLastUpdated() {
2668
2668
  return this.lastUpdated;
2669
2669
  }
2670
2670
  };
2671
- var isExpired = function isExpired2(now) {
2671
+ var isExpired = function isExpired2(now2) {
2672
2672
  if (!RuleCache.getLastUpdated()) {
2673
2673
  return true;
2674
2674
  }
2675
- return now > RuleCache.getLastUpdated() + TTL;
2675
+ return now2 > RuleCache.getLastUpdated() + TTL;
2676
2676
  };
2677
2677
  module2.exports = RuleCache;
2678
2678
  }
@@ -2713,13 +2713,13 @@ var require_rule_poller = __commonJS({
2713
2713
  }
2714
2714
  };
2715
2715
  var refreshCache = function refreshCache2() {
2716
- var now = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2716
+ var now2 = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2717
2717
  ServiceConnector.fetchSamplingRules(function(err, newRules) {
2718
2718
  if (err) {
2719
2719
  logger.getLogger().warn("Failed to retrieve sampling rules from X-Ray service:", err);
2720
2720
  } else if (newRules.length !== 0) {
2721
2721
  ruleCache.loadRules(newRules);
2722
- ruleCache.timestamp(now);
2722
+ ruleCache.timestamp(now2);
2723
2723
  logger.getLogger().info("Successfully refreshed centralized sampling rule cache.");
2724
2724
  }
2725
2725
  });
@@ -2815,11 +2815,11 @@ var require_default_sampler = __commonJS({
2815
2815
  if (!sampleRequest.serviceType) {
2816
2816
  sampleRequest.serviceType = SegmentUtils.origin;
2817
2817
  }
2818
- var now = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2819
- var matchedRule = this.ruleCache.getMatchedRule(sampleRequest, now);
2818
+ var now2 = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2819
+ var matchedRule = this.ruleCache.getMatchedRule(sampleRequest, now2);
2820
2820
  if (matchedRule) {
2821
2821
  logger.getLogger().debug(util.format("Rule %s is matched.", matchedRule.getName()));
2822
- return processMatchedRule(matchedRule, now);
2822
+ return processMatchedRule(matchedRule, now2);
2823
2823
  } else {
2824
2824
  logger.getLogger().info("No effective centralized sampling rule match. Fallback to local rules.");
2825
2825
  return this.localSampler.shouldSample(sampleRequest);
@@ -2849,11 +2849,11 @@ var require_default_sampler = __commonJS({
2849
2849
  }
2850
2850
  }
2851
2851
  };
2852
- var processMatchedRule = function processMatchedRule2(rule, now) {
2852
+ var processMatchedRule = function processMatchedRule2(rule, now2) {
2853
2853
  rule.incrementRequestCount();
2854
2854
  var reservoir = rule.getReservoir();
2855
2855
  var sample = true;
2856
- var decision = reservoir.borrowOrTake(now, rule.canBorrow());
2856
+ var decision = reservoir.borrowOrTake(now2, rule.canBorrow());
2857
2857
  if (decision === "borrow") {
2858
2858
  rule.incrementBorrowCount();
2859
2859
  } else if (decision === "take") {
@@ -5919,7 +5919,7 @@ var require_lru_cache = __commonJS({
5919
5919
  maxAge = maxAge || this[MAX_AGE];
5920
5920
  if (maxAge && typeof maxAge !== "number")
5921
5921
  throw new TypeError("maxAge must be a number");
5922
- const now = maxAge ? Date.now() : 0;
5922
+ const now2 = maxAge ? Date.now() : 0;
5923
5923
  const len = this[LENGTH_CALCULATOR](value, key);
5924
5924
  if (this[CACHE].has(key)) {
5925
5925
  if (len > this[MAX]) {
@@ -5932,7 +5932,7 @@ var require_lru_cache = __commonJS({
5932
5932
  if (!this[NO_DISPOSE_ON_SET])
5933
5933
  this[DISPOSE](key, item.value);
5934
5934
  }
5935
- item.now = now;
5935
+ item.now = now2;
5936
5936
  item.maxAge = maxAge;
5937
5937
  item.value = value;
5938
5938
  this[LENGTH] += len - item.length;
@@ -5941,7 +5941,7 @@ var require_lru_cache = __commonJS({
5941
5941
  trim(this);
5942
5942
  return true;
5943
5943
  }
5944
- const hit = new Entry(key, value, len, now, maxAge);
5944
+ const hit = new Entry(key, value, len, now2, maxAge);
5945
5945
  if (hit.length > this[MAX]) {
5946
5946
  if (this[DISPOSE])
5947
5947
  this[DISPOSE](key, value);
@@ -5977,14 +5977,14 @@ var require_lru_cache = __commonJS({
5977
5977
  }
5978
5978
  load(arr) {
5979
5979
  this.reset();
5980
- const now = Date.now();
5980
+ const now2 = Date.now();
5981
5981
  for (let l = arr.length - 1; l >= 0; l--) {
5982
5982
  const hit = arr[l];
5983
5983
  const expiresAt = hit.e || 0;
5984
5984
  if (expiresAt === 0)
5985
5985
  this.set(hit.k, hit.v);
5986
5986
  else {
5987
- const maxAge = expiresAt - now;
5987
+ const maxAge = expiresAt - now2;
5988
5988
  if (maxAge > 0) {
5989
5989
  this.set(hit.k, hit.v, maxAge);
5990
5990
  }
@@ -6039,11 +6039,11 @@ var require_lru_cache = __commonJS({
6039
6039
  }
6040
6040
  };
6041
6041
  var Entry = class {
6042
- constructor(key, value, length, now, maxAge) {
6042
+ constructor(key, value, length, now2, maxAge) {
6043
6043
  this.key = key;
6044
6044
  this.value = value;
6045
6045
  this.length = length;
6046
- this.now = now;
6046
+ this.now = now2;
6047
6047
  this.maxAge = maxAge || 0;
6048
6048
  }
6049
6049
  };
@@ -8115,11 +8115,15 @@ function integrity(input, tarball, alg = ((_a) => (_a = input.integrity) == null
8115
8115
  };
8116
8116
  }
8117
8117
 
8118
+ // src/backend/shared/time.lambda-shared.ts
8119
+ var now = Date.now;
8120
+
8118
8121
  // src/backend/ingestion/re-ingest.lambda.ts
8119
8122
  async function handler(event, context) {
8120
8123
  console.log("Event: ", JSON.stringify(event, null, 2));
8121
8124
  const bucket = requireEnv("BUCKET_NAME");
8122
8125
  const queueUrl = requireEnv("QUEUE_URL");
8126
+ const age = requireEnv("REPROCESS_AGE_MILLIS");
8123
8127
  console.log(`Download metadata object at ${bucket}/${event.Key}`);
8124
8128
  const { Body: jsonMetadata } = await s3().getObject({ Bucket: bucket, Key: event.Key }).promise();
8125
8129
  if (jsonMetadata == null) {
@@ -8131,7 +8135,13 @@ async function handler(event, context) {
8131
8135
  0,
8132
8136
  event.Key.length - METADATA_KEY_SUFFIX.length
8133
8137
  )}${PACKAGE_KEY_SUFFIX}`;
8134
- console.log(`Download metadata object at ${bucket}/${tarballKey}`);
8138
+ if (!isYoungEnough(time, Number(age))) {
8139
+ console.log(
8140
+ `Tarball ${tarballKey} has been published too far in the past (${age}). Not reprocessing`
8141
+ );
8142
+ return;
8143
+ }
8144
+ console.log(`Download tarball object at ${bucket}/${tarballKey}`);
8135
8145
  const { Body: tarball, VersionId: versionId } = await s3().getObject({ Bucket: bucket, Key: tarballKey }).promise();
8136
8146
  if (tarball == null) {
8137
8147
  console.error(`No body found in ${bucket}/${tarballKey}, aborting.`);
@@ -8176,6 +8186,10 @@ async function handler(event, context) {
8176
8186
  }
8177
8187
  }).promise();
8178
8188
  }
8189
+ function isYoungEnough(publishDate, historyTimeWindow) {
8190
+ const publish = new Date(publishDate).getTime();
8191
+ return publish + historyTimeWindow >= now();
8192
+ }
8179
8193
  // Annotate the CommonJS export names for ESM import in node:
8180
8194
  0 && (module.exports = {
8181
8195
  handler