Skip to content

Commit

Permalink
make action state transitions only happen once
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed May 28, 2024
1 parent 8745abb commit e6c5149
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions worker/paidAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export async function settleAction ({ data: { invoiceId }, models }) {
where: { id: invoiceId }
})

// TODO: ensure that this is done only once
await models.$transaction([
// optimistic concurrency control (aborts if invoice is not in PENDING state)
models.invoice.update({
where: { id: invoice.id },
where: { id: invoice.id, actionState: 'PENDING' },
data: { actionState: 'PAID' }
}),
...await paidActions[invoice.actionType].onPaidStatements({ invoice }, { models })
Expand All @@ -20,10 +20,10 @@ export async function settleActionError ({ data: { invoiceId }, models }) {
where: { id: invoiceId }
})

// TODO: ensure that this is done only once
await models.$transaction([
// optimistic concurrency control (aborts if invoice is not in PENDING state)
models.invoice.update({
where: { id: invoice.id },
where: { id: invoice.id, actionState: 'PENDING' },
data: { actionState: 'FAILED' }
}),
...await paidActions[invoice.actionType].onFailedStatements({ invoice }, { models })
Expand Down

0 comments on commit e6c5149

Please sign in to comment.