Skip to content

Commit

Permalink
use single pg client
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Jan 4, 2024
1 parent 15b117d commit 5db434a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions spark-publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ export const publish = async ({
const ieAddMeasurementsDuration = new Date() - start
logger.log('Measurements added to round', roundIndex.toString())

const pgClient = await client.connect()
try {
await client.query('BEGIN')
await pgClient.query('BEGIN')

// Mark measurements as shared
await client.query(`
await pgClient.query(`
UPDATE measurements
SET published_as = $1
WHERE id = ANY($2::int[])
Expand All @@ -81,14 +82,16 @@ export const publish = async ({

// Record the commitment for future queries
// TODO: store also ieContract.address and roundIndex
await client.query('INSERT INTO commitments (cid, published_at) VALUES ($1, $2)', [
await pgClient.query('INSERT INTO commitments (cid, published_at) VALUES ($1, $2)', [
cid.toString(), new Date()
])

await client.query('COMMIT')
await pgClient.query('COMMIT')
} catch (err) {
await client.query('ROLLBACK')
await pgClient.query('ROLLBACK')
throw err
} finally {
pgClient.release()
}

// TODO: Add cleanup
Expand Down

0 comments on commit 5db434a

Please sign in to comment.