From 8cd965eec04e8f8242fc1af71faf87bedfe561d0 Mon Sep 17 00:00:00 2001 From: Charles Morin Date: Wed, 18 Oct 2023 16:59:13 -0400 Subject: [PATCH] Removed mentions of the word 'restart' for inactivity --- README.md | 2 +- src/commander.ts | 6 +++--- src/config.ts | 2 +- src/{restartInactivitySeconds.ts => inactivitySeconds.ts} | 6 +++--- src/setup.ts | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) rename src/{restartInactivitySeconds.ts => inactivitySeconds.ts} (74%) diff --git a/README.md b/README.md index bf20f81..f76e744 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Options: --cursor-path File path or URL to cursor lock file (default: "cursor.lock", env: CURSOR_PATH) --http-cursor-auth Basic auth credentials for http cursor (ex: username:password) (env: HTTP_CURSOR_AUTH) --production-mode Enable production mode, allows cached substreams data if available (default: "false", env: PRODUCTION_MODE) - --restart-inactivity-seconds If set, the sink will restart when inactive for over a certain amount of seconds (default: 300, env: RESTART_INACTIVITY_SECONDS) + --inactivity-seconds If set, the sink will stop when inactive for over a certain amount of seconds (default: 300, env: INACTIVITY_SECONDS) --hostname The process will listen on this hostname for any HTTP and Prometheus metrics requests (default: "localhost", env: HOSTNAME) --port The process will listen on this port for any HTTP and Prometheus metrics requests (default: 9102, env: PORT) --metrics-labels [string...] To apply generic labels to all default metrics (ex: --labels foo=bar) (default: {}, env: METRICS_LABELS) diff --git a/src/commander.ts b/src/commander.ts index 1d96615..0203aff 100644 --- a/src/commander.ts +++ b/src/commander.ts @@ -1,6 +1,6 @@ import "dotenv/config"; import { Command, Option } from "commander"; -import { DEFAULT_CURSOR_PATH, DEFAULT_RESTART_INACTIVITY_SECONDS, DEFAULT_PARAMS, DEFAULT_SUBSTREAMS_API_TOKEN, DEFAULT_AUTH_ISSUE_URL, DEFAULT_VERBOSE, DEFAULT_HOSTNAME, DEFAULT_PORT, DEFAULT_METRICS_LABELS, DEFAULT_COLLECT_DEFAULT_METRICS, DEFAULT_START_BLOCK, DEFAULT_DELAY_BEFORE_START, DEFAULT_HEADERS, DEFAULT_PRODUCTION_MODE, DEFAULT_FINAL_BLOCKS_ONLY } from "./config.js"; +import { DEFAULT_CURSOR_PATH, DEFAULT_INACTIVITY_SECONDS, DEFAULT_PARAMS, DEFAULT_SUBSTREAMS_API_TOKEN, DEFAULT_AUTH_ISSUE_URL, DEFAULT_VERBOSE, DEFAULT_HOSTNAME, DEFAULT_PORT, DEFAULT_METRICS_LABELS, DEFAULT_COLLECT_DEFAULT_METRICS, DEFAULT_START_BLOCK, DEFAULT_DELAY_BEFORE_START, DEFAULT_HEADERS, DEFAULT_PRODUCTION_MODE, DEFAULT_FINAL_BLOCKS_ONLY } from "./config.js"; import { list } from "./list.js"; import { logger } from "./logger.js"; @@ -24,7 +24,7 @@ export interface RunOptions { cursorPath: string; httpCursorAuth: string; productionMode: string; - restartInactivitySeconds: number; + inactivitySeconds: number; hostname: string; port: number; metricsLabels: string[]; @@ -94,7 +94,7 @@ export function run(program: Command, pkg: Package) { .addOption(new Option("--cursor-path ", "File path or URL to cursor lock file").default(DEFAULT_CURSOR_PATH).env("CURSOR_PATH")) .addOption(new Option("--http-cursor-auth ", "Basic auth credentials for http cursor (ex: username:password)").env("HTTP_CURSOR_AUTH").argParser(handleHttpCursorAuth)) .addOption(new Option("--production-mode ", "Enable production mode, allows cached substreams data if available").default(DEFAULT_PRODUCTION_MODE).env("PRODUCTION_MODE")) - .addOption(new Option("--restart-inactivity-seconds ", "If set, the sink will restart when inactive for over a certain amount of seconds").default(DEFAULT_RESTART_INACTIVITY_SECONDS).env("RESTART_INACTIVITY_SECONDS")) + .addOption(new Option("--inactivity-seconds ", "If set, the sink will stop when inactive for over a certain amount of seconds").default(DEFAULT_INACTIVITY_SECONDS).env("INACTIVITY_SECONDS")) .addOption(new Option("--hostname ", "The process will listen on this hostname for any HTTP and Prometheus metrics requests").default(DEFAULT_HOSTNAME).env("HOSTNAME")) .addOption(new Option("--port ", "The process will listen on this port for any HTTP and Prometheus metrics requests").default(DEFAULT_PORT).env("PORT")) .addOption(new Option("--metrics-labels [string...]", "To apply generic labels to all default metrics (ex: --labels foo=bar)").default(DEFAULT_METRICS_LABELS).env("METRICS_LABELS").argParser(handleMetricsLabels)) diff --git a/src/config.ts b/src/config.ts index 308b9ff..1e0b3bb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,7 @@ export const DEFAULT_HOSTNAME = "localhost"; export const DEFAULT_PORT = 9102; export const DEFAULT_CURSOR_PATH = "cursor.lock"; export const DEFAULT_VERBOSE = "false"; -export const DEFAULT_RESTART_INACTIVITY_SECONDS = 300; +export const DEFAULT_INACTIVITY_SECONDS = 300; export const DEFAULT_PRODUCTION_MODE = "false"; export const DEFAULT_DELAY_BEFORE_START = 0; export const DEFAULT_METRICS_LABELS = {}; diff --git a/src/restartInactivitySeconds.ts b/src/inactivitySeconds.ts similarity index 74% rename from src/restartInactivitySeconds.ts rename to src/inactivitySeconds.ts index 83f9ddf..926aeeb 100644 --- a/src/restartInactivitySeconds.ts +++ b/src/inactivitySeconds.ts @@ -4,13 +4,13 @@ import { logger } from "./logger.js"; const CHECK_INACTIVITY_INTERVAL = 1000; -export function onRestartInactivitySeconds(emitter: BlockEmitter, restartInactivitySeconds: number, hasStopBlock: boolean) { +export function onInactivitySeconds(emitter: BlockEmitter, inactivitySeconds: number, hasStopBlock: boolean) { let lastUpdate = now(); let isFinished = false; async function checkInactivity() { - if (now() - lastUpdate > restartInactivitySeconds) { - logger.error(`Restarting due to inactivity for ${restartInactivitySeconds} seconds`); + if (now() - lastUpdate > inactivitySeconds) { + logger.error(`Process will exit due to inactivity for ${inactivitySeconds} seconds`); process.exit(1); // force quit } if (isFinished) return; // exit out of the loop diff --git a/src/setup.ts b/src/setup.ts index 2c2b95d..9c63bca 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -8,7 +8,7 @@ import * as fileCursor from "./cursor/fileCursor.js"; import * as httpCursor from "./cursor/httpCursor.js"; import * as prometheus from "./prometheus.js"; import { logger } from "./logger.js"; -import { onRestartInactivitySeconds } from "./restartInactivitySeconds.js"; +import { onInactivitySeconds } from "./inactivitySeconds.js"; import { applyParams } from "./applyParams.js"; import { health } from "./health.js"; @@ -84,8 +84,8 @@ export async function setup(options: RunOptions) { // Adds delay before using sink await setTimeout(options.delayBeforeStart); - // Restart on inactivity - onRestartInactivitySeconds(emitter, options.restartInactivitySeconds, stopBlockNum !== undefined); + // Stop on inactivity + onInactivitySeconds(emitter, options.inactivitySeconds, stopBlockNum !== undefined); return { emitter, substreamPackage, moduleHash, startCursor }; } \ No newline at end of file