@noosphere/agent-core 0.1.0-alpha.11 → 0.1.0-alpha.12
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.cjs +51 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -812,7 +812,13 @@ var SchedulerService = class extends import_events2.EventEmitter {
|
|
|
812
812
|
try {
|
|
813
813
|
currentInterval = BigInt(await this.router.getComputeSubscriptionInterval(sub.subscriptionId));
|
|
814
814
|
} catch (error) {
|
|
815
|
-
|
|
815
|
+
const errorMessage = error.message || "";
|
|
816
|
+
console.warn(` Could not get interval from router for subscription ${subId}:`, errorMessage);
|
|
817
|
+
if (errorMessage.includes("SubscriptionNotFound")) {
|
|
818
|
+
console.log(` Subscription ${subId} not found (cancelled), untracking...`);
|
|
819
|
+
this.untrackSubscription(sub.subscriptionId);
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
816
822
|
const intervalsSinceActive = BigInt(currentBlockTime) - sub.activeAt;
|
|
817
823
|
currentInterval = intervalsSinceActive / sub.intervalSeconds + 1n;
|
|
818
824
|
}
|
|
@@ -1480,6 +1486,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1480
1486
|
}
|
|
1481
1487
|
this.maxRetries = options.maxRetries ?? 3;
|
|
1482
1488
|
this.retryIntervalMs = options.retryIntervalMs ?? 3e4;
|
|
1489
|
+
this.containerTimeout = options.containerConfig?.timeout ?? 3e5;
|
|
1490
|
+
this.containerConnectionRetries = options.containerConfig?.connectionRetries ?? 5;
|
|
1491
|
+
this.containerConnectionRetryDelayMs = options.containerConfig?.connectionRetryDelayMs ?? 3e3;
|
|
1492
|
+
this.healthCheckIntervalMs = options.healthCheckIntervalMs ?? 3e5;
|
|
1483
1493
|
}
|
|
1484
1494
|
/**
|
|
1485
1495
|
* Initialize NoosphereAgent from config.json (RECOMMENDED)
|
|
@@ -1621,6 +1631,7 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1621
1631
|
if (this.options.getRetryableEvents && this.options.resetEventForRetry) {
|
|
1622
1632
|
this.startRetryTimer();
|
|
1623
1633
|
}
|
|
1634
|
+
this.startHealthCheck();
|
|
1624
1635
|
this.isRunning = true;
|
|
1625
1636
|
console.log("\u2713 Noosphere Agent is running");
|
|
1626
1637
|
console.log("Listening for requests...");
|
|
@@ -1637,6 +1648,38 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1637
1648
|
await this.processRetries();
|
|
1638
1649
|
}, this.retryIntervalMs);
|
|
1639
1650
|
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Start the health check timer for registry validation
|
|
1653
|
+
*/
|
|
1654
|
+
startHealthCheck() {
|
|
1655
|
+
if (this.healthCheckTimer) {
|
|
1656
|
+
clearInterval(this.healthCheckTimer);
|
|
1657
|
+
}
|
|
1658
|
+
console.log(`\u{1F3E5} Health check enabled: check every ${this.healthCheckIntervalMs / 1e3}s`);
|
|
1659
|
+
this.healthCheckTimer = setInterval(async () => {
|
|
1660
|
+
await this.performHealthCheck();
|
|
1661
|
+
}, this.healthCheckIntervalMs);
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Perform health check - verify registry has containers and reload if necessary
|
|
1665
|
+
*/
|
|
1666
|
+
async performHealthCheck() {
|
|
1667
|
+
const stats = this.registryManager.getStats();
|
|
1668
|
+
if (stats.totalContainers === 0) {
|
|
1669
|
+
console.warn("\u26A0\uFE0F Health check: 0 containers detected, attempting registry reload...");
|
|
1670
|
+
try {
|
|
1671
|
+
await this.registryManager.reload();
|
|
1672
|
+
const newStats = this.registryManager.getStats();
|
|
1673
|
+
if (newStats.totalContainers > 0) {
|
|
1674
|
+
console.log(`\u2713 Health check: Registry recovered - ${newStats.totalContainers} containers loaded`);
|
|
1675
|
+
} else {
|
|
1676
|
+
console.error("\u274C Health check: Registry reload failed - still 0 containers");
|
|
1677
|
+
}
|
|
1678
|
+
} catch (error) {
|
|
1679
|
+
console.error("\u274C Health check: Registry reload error:", error.message);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1640
1683
|
/**
|
|
1641
1684
|
* Process retryable failed events (with throttling to avoid rate limits)
|
|
1642
1685
|
*/
|
|
@@ -1823,8 +1866,9 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1823
1866
|
const result = await this.containerManager.runContainer(
|
|
1824
1867
|
container,
|
|
1825
1868
|
inputData,
|
|
1826
|
-
|
|
1827
|
-
|
|
1869
|
+
this.containerTimeout,
|
|
1870
|
+
this.containerConnectionRetries,
|
|
1871
|
+
this.containerConnectionRetryDelayMs
|
|
1828
1872
|
);
|
|
1829
1873
|
if (result.exitCode !== 0) {
|
|
1830
1874
|
console.error(` \u274C Container execution failed with exit code ${result.exitCode}`);
|
|
@@ -1919,6 +1963,10 @@ var NoosphereAgent = class _NoosphereAgent {
|
|
|
1919
1963
|
clearInterval(this.retryTimer);
|
|
1920
1964
|
this.retryTimer = void 0;
|
|
1921
1965
|
}
|
|
1966
|
+
if (this.healthCheckTimer) {
|
|
1967
|
+
clearInterval(this.healthCheckTimer);
|
|
1968
|
+
this.healthCheckTimer = void 0;
|
|
1969
|
+
}
|
|
1922
1970
|
await this.eventMonitor.stop();
|
|
1923
1971
|
this.scheduler.stop();
|
|
1924
1972
|
await this.containerManager.cleanup();
|