Skip to content

Commit

Permalink
feat: retry role creation as this frequently fails with: tuple concur…
Browse files Browse the repository at this point in the history
…rently updated
  • Loading branch information
dnz-bdeboer committed Jun 11, 2024
1 parent c5bfbec commit 6c66ebf
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,26 @@ export const handler = async (
const pg_client = new Client(params)
await pg_client.connect()
try {
if (typeof sql === "string") {
await pg_client.query(sql)
} else {
await Promise.all(
sql.map(async (statement) => {
await pg_client.query(statement)
})
)
}
await backOff(
async () => {
if (typeof sql === "string") {
return pg_client.query(sql)
} else {
if (sql) {
return Promise.all(
sql.map((statement) => {
return pg_client.query(statement)
})
)
} else {
return
}
}
},
{
retry: errorFilter,
}
)
} finally {
await pg_client.end()
}
Expand All @@ -329,6 +340,14 @@ export const handler = async (
return response
}

// Custom error filter, mainly to retry role creation.
// Frequently see "tuple concurrently updated", and adding
// dependencies is very hard to make work.
const errorFilter = (error: any) => {
// Retry only if the error message contains "tuple concurrently updated"
return error.message.includes("tuple concurrently updated")
}

/**
* Parse password field from secret. Returns void on error.
*/
Expand Down

0 comments on commit 6c66ebf

Please sign in to comment.