Chore: move tx code into atomic function
This commit is contained in:
parent
8cd1389de3
commit
4f12bcf4cf
4 changed files with 12 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const _ = require('lodash/fp')
|
||||
const pgp = require('pg-promise')()
|
||||
|
||||
const db = require('../db')
|
||||
const E = require('../error')
|
||||
|
||||
const cashInLow = require('./cash-in-low')
|
||||
|
|
@ -8,6 +9,9 @@ const cashInLow = require('./cash-in-low')
|
|||
module.exports = { atomic }
|
||||
|
||||
function atomic (machineTx, pi) {
|
||||
const TransactionMode = pgp.txMode.TransactionMode
|
||||
const isolationLevel = pgp.txMode.isolationLevel
|
||||
const mode = new TransactionMode({ tiLevel: isolationLevel.serializable })
|
||||
function transaction (t) {
|
||||
const sql = 'select * from cash_in_txs where id=$1'
|
||||
const sql2 = 'select * from bills where cash_in_txs_id=$1'
|
||||
|
|
@ -29,7 +33,7 @@ function atomic (machineTx, pi) {
|
|||
})
|
||||
})
|
||||
}
|
||||
return transaction
|
||||
return db.tx({ mode }, transaction)
|
||||
}
|
||||
|
||||
function insertNewBills (t, billRows, machineTx) {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,7 @@ const MAX_PENDING = 10
|
|||
module.exports = { post, monitorPending, cancel, PENDING_INTERVAL }
|
||||
|
||||
function post (machineTx, pi) {
|
||||
const TransactionMode = pgp.txMode.TransactionMode
|
||||
const isolationLevel = pgp.txMode.isolationLevel
|
||||
const mode = new TransactionMode({ tiLevel: isolationLevel.serializable })
|
||||
|
||||
return db.tx({ mode }, cashInAtomic.atomic(machineTx, pi))
|
||||
return cashInAtomic.atomic(machineTx, pi)
|
||||
.then(r => {
|
||||
const updatedTx = r.tx
|
||||
let blacklisted = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue