diff --git a/index.ts b/index.ts index c98ffad..76a540b 100644 --- a/index.ts +++ b/index.ts @@ -66,6 +66,9 @@ export async function action(options: CSVRunOptions ) { let resolvedStartBlock = 0; let maxParallelWorkers = 0; let runningJobs = 0; + let last_seconds = 0; + let start = Math.floor(Date.now() / 1000); // seconds + let last_update = 0; emitter.on("session", (session) => { fs.writeFileSync(sessionFile, JSON.stringify(session, null, 2)); @@ -96,6 +99,7 @@ export async function action(options: CSVRunOptions ) { const { block_num, block_id, timestamp, seconds } = parseClock(clock); last_block_num = block_num; last_timestamp = timestamp; + last_seconds = seconds; // block header for ( const entityChange of EntityChanges.parse(data).entityChanges ) { @@ -132,7 +136,12 @@ export async function action(options: CSVRunOptions ) { }); function log() { - logUpdate(JSON.stringify({last_block_num, last_timestamp, blocks, rows, totalBytesRead, totalBytesWritten, runningJobs})); + const now = Math.floor(Date.now() / 1000); + if ( last_update != now) { + last_update = now; + const blocksPerSecond = Math.floor(blocks / (last_update - start)); + logUpdate(JSON.stringify({last_block_num, last_timestamp, blocks, rows, blocksPerSecond, totalBytesRead, totalBytesWritten, runningJobs})); + } } fileCursor.onCursor(emitter, cursorFile); diff --git a/package-lock.json b/package-lock.json index 85c64ce..7f502bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "substreams-sink-csv", - "version": "0.2.3", + "version": "0.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "substreams-sink-csv", - "version": "0.2.3", + "version": "0.2.7", "dependencies": { "@substreams/sink-entity-changes": "^0.3.9", "log-update": "latest", - "substreams-sink": "^0.15.1" + "substreams-sink": "^0.15.2" }, "bin": { "substreams-sink-csv": "dist/bin/cli.js" @@ -565,9 +565,9 @@ } }, "node_modules/substreams-sink": { - "version": "0.15.1", - "resolved": "https://registry.npmjs.org/substreams-sink/-/substreams-sink-0.15.1.tgz", - "integrity": "sha512-oKm4Aln3AoYienp2lAtVW4gl2FEH33FK0riCh1aaOyGJq8N+JwM2yFf38qVI+/mnX53tEXgi+ema/NfeF0zY0A==", + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/substreams-sink/-/substreams-sink-0.15.2.tgz", + "integrity": "sha512-nbvdn1a4pcOlf2NIkzTcZS2aa5Cv0pBWJ17jxvBoSRyHDCw/tTFivsJAwsrdNGgs7srQLhGVtn1nwmxezsR+UA==", "dependencies": { "@substreams/core": "^0.15.1", "@substreams/manifest": "^0.14.1", diff --git a/package.json b/package.json index a7b49e3..36b55b7 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "dependencies": { "@substreams/sink-entity-changes": "^0.3.9", "log-update": "latest", - "substreams-sink": "^0.15.1" + "substreams-sink": "^0.15.2" }, "devDependencies": { "@types/bun": "latest",