Skip to content

Commit

Permalink
Removed mentions of the word 'restart' for inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
chamorin committed Oct 18, 2023
1 parent 97a4d93 commit 8cd965e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Options:
--cursor-path <string> File path or URL to cursor lock file (default: "cursor.lock", env: CURSOR_PATH)
--http-cursor-auth <string> Basic auth credentials for http cursor (ex: username:password) (env: HTTP_CURSOR_AUTH)
--production-mode <boolean> Enable production mode, allows cached substreams data if available (default: "false", env: PRODUCTION_MODE)
--restart-inactivity-seconds <int> If set, the sink will restart when inactive for over a certain amount of seconds (default: 300, env: RESTART_INACTIVITY_SECONDS)
--inactivity-seconds <int> If set, the sink will stop when inactive for over a certain amount of seconds (default: 300, env: INACTIVITY_SECONDS)
--hostname <string> The process will listen on this hostname for any HTTP and Prometheus metrics requests (default: "localhost", env: HOSTNAME)
--port <int> 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)
Expand Down
6 changes: 3 additions & 3 deletions src/commander.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,7 +24,7 @@ export interface RunOptions {
cursorPath: string;
httpCursorAuth: string;
productionMode: string;
restartInactivitySeconds: number;
inactivitySeconds: number;
hostname: string;
port: number;
metricsLabels: string[];
Expand Down Expand Up @@ -94,7 +94,7 @@ export function run(program: Command, pkg: Package) {
.addOption(new Option("--cursor-path <string>", "File path or URL to cursor lock file").default(DEFAULT_CURSOR_PATH).env("CURSOR_PATH"))
.addOption(new Option("--http-cursor-auth <string>", "Basic auth credentials for http cursor (ex: username:password)").env("HTTP_CURSOR_AUTH").argParser(handleHttpCursorAuth))
.addOption(new Option("--production-mode <boolean>", "Enable production mode, allows cached substreams data if available").default(DEFAULT_PRODUCTION_MODE).env("PRODUCTION_MODE"))
.addOption(new Option("--restart-inactivity-seconds <int>", "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 <int>", "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 <string>", "The process will listen on this hostname for any HTTP and Prometheus metrics requests").default(DEFAULT_HOSTNAME).env("HOSTNAME"))
.addOption(new Option("--port <int>", "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))
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
6 changes: 3 additions & 3 deletions src/restartInactivitySeconds.ts → src/inactivitySeconds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 };
}

0 comments on commit 8cd965e

Please sign in to comment.