@secondlayer/subgraphs 1.3.0 → 1.3.1

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.
@@ -1440,6 +1440,7 @@ function avgEventsPerBlock(batch) {
1440
1440
 
1441
1441
  // src/runtime/reindex.ts
1442
1442
  var LOG_INTERVAL = 1000;
1443
+ var HEALTH_FLUSH_INTERVAL = 1000;
1443
1444
  var HOBBY_REINDEX_BATCH_CONFIG = {
1444
1445
  defaultBatchSize: 50,
1445
1446
  minBatchSize: 25,
@@ -1510,10 +1511,23 @@ async function processBlockRange(def, opts) {
1510
1511
  let blocksProcessed = 0;
1511
1512
  let totalEventsProcessed = 0;
1512
1513
  let totalErrors = 0;
1514
+ let pendingEventsProcessed = 0;
1515
+ let pendingErrors = 0;
1516
+ let pendingLastError;
1517
+ let lastHealthFlushBlock = 0;
1513
1518
  const batchConfig = resolveReindexBatchConfig();
1514
1519
  let batchSize = batchConfig.defaultBatchSize;
1515
1520
  let currentHeight = fromBlock;
1516
1521
  let aborted = false;
1522
+ const flushHealth = async () => {
1523
+ if (pendingEventsProcessed === 0 && pendingErrors === 0)
1524
+ return;
1525
+ await recordSubgraphProcessed2(targetDb, subgraphName, pendingEventsProcessed, pendingErrors, pendingLastError);
1526
+ pendingEventsProcessed = 0;
1527
+ pendingErrors = 0;
1528
+ pendingLastError = undefined;
1529
+ lastHealthFlushBlock = blocksProcessed;
1530
+ };
1517
1531
  let nextBatchEnd = Math.min(currentHeight + batchSize - 1, toBlock);
1518
1532
  let nextBatchPromise = loadBlockRange(sourceDb, currentHeight, nextBatchEnd);
1519
1533
  while (currentHeight <= toBlock) {
@@ -1556,14 +1570,20 @@ async function processBlockRange(def, opts) {
1556
1570
  });
1557
1571
  batchFailedBlocks.push({ height, reason: "processing_error" });
1558
1572
  await updateSubgraphStatus2(targetDb, subgraphName, status, height).catch(() => {});
1559
- await recordSubgraphProcessed2(targetDb, subgraphName, 0, 1, errorMsg).catch(() => {});
1560
1573
  blocksProcessed++;
1561
1574
  totalErrors++;
1575
+ pendingErrors++;
1576
+ pendingLastError = errorMsg;
1562
1577
  continue;
1563
1578
  }
1564
1579
  blocksProcessed++;
1565
1580
  totalEventsProcessed += result.processed;
1566
1581
  totalErrors += result.errors;
1582
+ pendingEventsProcessed += result.processed;
1583
+ pendingErrors += result.errors;
1584
+ if (result.errors > 0) {
1585
+ pendingLastError = `${result.errors} error(s) while processing block ${height}`;
1586
+ }
1567
1587
  if (result.timing) {
1568
1588
  stats.record(result.timing, result.processed);
1569
1589
  if (stats.shouldFlush()) {
@@ -1583,6 +1603,9 @@ async function processBlockRange(def, opts) {
1583
1603
  });
1584
1604
  }
1585
1605
  }
1606
+ if (blocksProcessed - lastHealthFlushBlock >= HEALTH_FLUSH_INTERVAL) {
1607
+ await flushHealth();
1608
+ }
1586
1609
  if (batchFailedBlocks.length > 0 && opts.subgraphId) {
1587
1610
  const gaps = coalesceFailedBlocks(batchFailedBlocks);
1588
1611
  await recordGapBatch(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
@@ -1600,6 +1623,7 @@ async function processBlockRange(def, opts) {
1600
1623
  currentHeight = batchEnd + 1;
1601
1624
  }
1602
1625
  await stats.flush(targetDb);
1626
+ await flushHealth();
1603
1627
  return { blocksProcessed, totalEventsProcessed, totalErrors, aborted };
1604
1628
  }
1605
1629
  async function resolveBlockRange(sourceDb, def, opts) {
@@ -1645,6 +1669,10 @@ async function reindexSubgraph(def, opts) {
1645
1669
  last_processed_block: initialReindexProgressBlock(fromBlock),
1646
1670
  reindex_from_block: fromBlock,
1647
1671
  reindex_to_block: toBlock,
1672
+ total_processed: 0,
1673
+ total_errors: 0,
1674
+ last_error: null,
1675
+ last_error_at: null,
1648
1676
  updated_at: new Date
1649
1677
  }).where("name", "=", subgraphName).execute();
1650
1678
  logger5.info("Reindexing blocks", {
@@ -1676,10 +1704,6 @@ async function reindexSubgraph(def, opts) {
1676
1704
  }
1677
1705
  return { processed: result.blocksProcessed };
1678
1706
  }
1679
- const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
1680
- if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
1681
- await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during reindex` : undefined);
1682
- }
1683
1707
  await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
1684
1708
  await clearReindexMetadata(targetDb, subgraphName);
1685
1709
  logger5.info("Reindex complete", {
@@ -1755,10 +1779,6 @@ async function resumeReindex(def, opts) {
1755
1779
  }
1756
1780
  return { processed: result.blocksProcessed };
1757
1781
  }
1758
- const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
1759
- if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
1760
- await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during resumed reindex` : undefined);
1761
- }
1762
1782
  await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
1763
1783
  await clearReindexMetadata(targetDb, subgraphName);
1764
1784
  logger5.info("Resumed reindex complete", {
@@ -1805,10 +1825,6 @@ async function backfillSubgraph(def, opts) {
1805
1825
  resolved
1806
1826
  });
1807
1827
  }
1808
- const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
1809
- if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
1810
- await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during backfill` : undefined);
1811
- }
1812
1828
  logger5.info("Backfill complete", {
1813
1829
  subgraph: subgraphName,
1814
1830
  blocks: result.blocksProcessed,
@@ -2921,5 +2937,5 @@ export {
2921
2937
  startSubgraphOperationRunner
2922
2938
  };
2923
2939
 
2924
- //# debugId=EB15298D4A41778164756E2164756E21
2940
+ //# debugId=1929DF522C4FE6AB64756E2164756E21
2925
2941
  //# sourceMappingURL=processor.js.map