Skip to content

Commit

Permalink
Fixed onRestartInactivitySeconds not stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
chamorin committed Sep 18, 2023
1 parent 041dd04 commit 0924096
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "substreams-sink",
"version": "0.9.5",
"version": "0.9.6",
"description": "Substreams Sink",
"type": "module",
"exports": "./dist/index.js",
Expand Down Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@substreams/core": "^0.1.19",
"@substreams/manifest": "^0.0.9",
"@substreams/node": "^0.2.1",
"@substreams/node": "^0.2.2",
"commander": "latest",
"dotenv": "latest",
"node-fetch": "latest",
Expand Down
8 changes: 5 additions & 3 deletions src/restartInactivitySeconds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from "./logger.js";

const CHECK_INACTIVITY_INTERVAL = 1000;

export function onRestartInactivitySeconds(emitter: BlockEmitter, restartInactivitySeconds: number) {
export function onRestartInactivitySeconds(emitter: BlockEmitter, restartInactivitySeconds: number, hasStopBlock: boolean) {
let lastUpdate = now();
let isFinished = false;

Expand All @@ -17,11 +17,13 @@ export function onRestartInactivitySeconds(emitter: BlockEmitter, restartInactiv
await setTimeout(CHECK_INACTIVITY_INTERVAL);
checkInactivity();
}

// Check for inactivity after starting
emitter.on("clock", clock => {
lastUpdate = now();
if (clock.number >= emitter.request.stopBlockNum - 1n) {
if (hasStopBlock && clock.number >= emitter.request.stopBlockNum - 1n) {
isFinished = true;
};
}
});
checkInactivity();
}
Expand Down
5 changes: 1 addition & 4 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ export async function setup(options: RunOptions) {
await setTimeout(options.delayBeforeStart);

// Restart on inactivity
// only activate once first cursor is received
emitter.once("cursor", () => {
onRestartInactivitySeconds(emitter, options.restartInactivitySeconds);
});
onRestartInactivitySeconds(emitter, options.restartInactivitySeconds, stopBlockNum !== undefined);

return { emitter, substreamPackage, moduleHash, startCursor };
}

0 comments on commit 0924096

Please sign in to comment.