Skip to content

Commit

Permalink
fix: Use better error handling inside replicator install()
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarek-kindred committed Sep 13, 2023
1 parent d9bc686 commit 1e2db85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cohort_banking_replicator_js/src/cfg/config-kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { JsKafkaConfig } from "cohort_sdk_js"
const kafkaConfig: JsKafkaConfig = {
brokers: ["127.0.0.1:9092"],
topic: "dev.ksp.certification",
clientId: "cohortr-replicator-js",
groupId: "cohortr-replicator-js",
clientId: "cohort-replicator-js3",
groupId: "cohort-replicator-js3",
producerSendTimeoutMs: 10,
logLevel: "info",
producerConfigOverrides: {},
Expand Down
18 changes: 13 additions & 5 deletions cohort_banking_replicator_js/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export class Database {
metric.callbackInstallCount++

try {
let recentError = null as any
while (attemptNr <= retry.maxAttempts) {
attemptNr++

if (attemptNr > retry.maxAttempts) {
const elapsedSec = (Date.now() - startedAt) / 1000.0
throw `Statemap install timed out after: ${elapsedSec} sec`
throw { message: `Statemap install timed out after: ${elapsedSec} sec`, error: recentError }
}

await cnn.query('BEGIN')
Expand Down Expand Up @@ -145,15 +146,22 @@ export class Database {
break

} catch (e) {
await cnn.query('ROLLBACK')
let error = { installError: e, rollbackError: null }
try {
await cnn.query('ROLLBACK')
} catch (e) {
error.rollbackError = e
} finally {
recentError = error
}

await new Promise(resolve => setTimeout(resolve, retry.delayMs))
}
}
} finally {
cnn?.release()
metric.attemptsUsed = attemptNr
this.metricsChannel.postMessage(metric)
}

metric.attemptsUsed = attemptNr
this.metricsChannel.postMessage(metric)
}
}

0 comments on commit 1e2db85

Please sign in to comment.