Skip to content

Commit

Permalink
update block info
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Jun 6, 2024
1 parent 3f0b680 commit 75396d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export async function action(options: CSVRunOptions ) {
// Stream Messages
emitter.on("anyMessage", async (data, cursor, clock) => {
const { block_number, timestamp, seconds } = parseClock(clock);
blocks += last_block_number ? block_number - last_block_number : 1;
last_block_number = block_number;
last_timestamp = timestamp;
last_seconds = seconds;


if (dataType == OutputType.EntityChanges) {
for ( const entityChange of EntityChanges.parse(data).entityChanges ) {
const writer = writers.get(entityChange.entity);
Expand Down Expand Up @@ -150,17 +150,15 @@ export async function action(options: CSVRunOptions ) {
}

// logging
blocks++;
log();
});

function log() {
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_number, last_timestamp, blocks, rows, blocksPerSecond, totalBytesRead, totalBytesWritten, runningJobs}));
}
if ( last_update == now ) return;
last_update = now;
const blocksPerSecond = Math.floor(blocks / (last_update - start));
logUpdate(JSON.stringify({last_block_number, last_timestamp, blocks, rows, blocksPerSecond, totalBytesRead, totalBytesWritten, runningJobs}));
}

fileCursor.onCursor(emitter, cursorFile);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.3.2",
"version": "0.3.3",
"name": "substreams-sink-csv",
"description": "Substreams Sink CSV",
"type": "module",
Expand Down

0 comments on commit 75396d7

Please sign in to comment.