Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setup a no-op PG client in dry-run #125

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}