Skip to content

Commit

Permalink
fix: setup a no-op PG client in dry-run (#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos authored Jan 17, 2024
1 parent adb1373 commit c31a660
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bin/dry-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ await evaluate({
fetchRoundDetails,
ieContractWithSigner,
logger: console,
recordTelemetry
recordTelemetry,

// We don't want dry runs to update data in `sparks_stats`, therefore we are passing a stub
// connection factory that creates no-op clients. This also keeps the setup simpler. The person
// executing a dry run does not need access to any Postgres instance.
// Evaluate uses the PG client only for updating the statistics, it's not reading any data.
// Thus it's safe to inject a no-op client.
createPgClient: createNoopPgClient
})

console.log(process.memoryUsage())
Expand Down Expand Up @@ -209,3 +216,14 @@ async function fetchMeasurementsAddedFromChain (roundIndex) {

return events.filter(e => e.roundIndex.eq(roundIndex)).map(e => e.cid)
}

function createNoopPgClient () {
return {
async query () {
return { rows: [] }
},
async end () {
// no-op
}
}
}

0 comments on commit c31a660

Please sign in to comment.