|
|
@@ -45,6 +45,8 @@ let walletTimeStamp: Date;
|
|
|
let maxPerBatch: number = 1;
|
|
|
let maxAttempts: number = 2;
|
|
|
let retryDelayInMs: number = 0;
|
|
|
+let maxHealthyNoRelayDurationInSeconds: number = 120;
|
|
|
+let lastSuccessfulRelayTime: Date;
|
|
|
|
|
|
export function init(runWorker: boolean, relay: Relay): boolean {
|
|
|
if (!runWorker) return true;
|
|
|
@@ -93,6 +95,20 @@ export function init(runWorker: boolean, relay: Relay): boolean {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (process.env.MAX_HEALTHY_NO_RELAY_DURATION_IN_SECONDS) {
|
|
|
+ maxHealthyNoRelayDurationInSeconds = parseInt(process.env.MAX_HEALTHY_NO_RELAY_DURATION_IN_SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxHealthyNoRelayDurationInSeconds <= 0) {
|
|
|
+ logger.error(
|
|
|
+ "Environment variable MAX_HEALTHY_NO_RELAY_DURATION_IN_SECONDS has an invalid value of " +
|
|
|
+ maxHealthyNoRelayDurationInSeconds +
|
|
|
+ ", must be positive."
|
|
|
+ );
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -392,6 +408,10 @@ async function finalizeEventsAlreadyLocked(
|
|
|
relayResult
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ if (relayResult.is_ok()) {
|
|
|
+ lastSuccessfulRelayTime = new Date();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async function updateBalance() {
|
|
|
@@ -474,3 +494,18 @@ export async function getPriceData(priceId: string): Promise<any> {
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+export function isHealthy(): boolean {
|
|
|
+ if (lastSuccessfulRelayTime === undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const currentDate = new Date();
|
|
|
+ const timeDiffMs = currentDate.getTime() - lastSuccessfulRelayTime.getTime();
|
|
|
+
|
|
|
+ if (timeDiffMs > maxHealthyNoRelayDurationInSeconds * 1000) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|