retry on serialization errors
This commit is contained in:
parent
0eabe1463d
commit
57e96ac02b
|
@ -1,22 +1,32 @@
|
||||||
const { UserInputError } = require('apollo-server-micro')
|
const { UserInputError } = require('apollo-server-micro')
|
||||||
|
const retry = require('async-retry')
|
||||||
|
|
||||||
async function serialize (models, call) {
|
async function serialize (models, call) {
|
||||||
try {
|
await retry(async bail => {
|
||||||
const [, result] = await models.$transaction([
|
try {
|
||||||
models.$executeRaw(SERIALIZE),
|
const [, result] = await models.$transaction([
|
||||||
call
|
models.$executeRaw(SERIALIZE),
|
||||||
])
|
call
|
||||||
return result
|
])
|
||||||
} catch (error) {
|
return result
|
||||||
console.log(error)
|
} catch (error) {
|
||||||
if (error.message.includes('SN_INSUFFICIENT_FUNDS')) {
|
console.log(error)
|
||||||
throw new UserInputError('insufficient funds')
|
if (error.message.includes('SN_INSUFFICIENT_FUNDS')) {
|
||||||
|
bail(new UserInputError('insufficient funds'))
|
||||||
|
}
|
||||||
|
if (error.message.includes('SN_NOT_SERIALIZABLE')) {
|
||||||
|
bail(new Error('wallet balance transaction is not serializable'))
|
||||||
|
}
|
||||||
|
if (error.message.includes('40001')) {
|
||||||
|
throw new Error('wallet balance serialization failure - retry again')
|
||||||
|
}
|
||||||
|
bail(error)
|
||||||
}
|
}
|
||||||
if (error.message.includes('SN_NOT_SERIALIZABLE')) {
|
}, {
|
||||||
throw new Error('wallet transaction isolation level is not serializable')
|
minTimeout: 100,
|
||||||
}
|
factor: 1.1,
|
||||||
throw error
|
retries: 5
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const SERIALIZE = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
|
const SERIALIZE = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"@apollo/client": "^3.3.13",
|
"@apollo/client": "^3.3.13",
|
||||||
"@prisma/client": "^2.22.1",
|
"@prisma/client": "^2.22.1",
|
||||||
"apollo-server-micro": "^2.21.2",
|
"apollo-server-micro": "^2.21.2",
|
||||||
|
"async-retry": "^1.3.1",
|
||||||
"bootstrap": "^4.6.0",
|
"bootstrap": "^4.6.0",
|
||||||
"clipboard-copy": "^4.0.1",
|
"clipboard-copy": "^4.0.1",
|
||||||
"formik": "^2.2.6",
|
"formik": "^2.2.6",
|
||||||
|
@ -46,4 +47,4 @@
|
||||||
"prisma": "^2.22.1",
|
"prisma": "^2.22.1",
|
||||||
"standard": "^16.0.3"
|
"standard": "^16.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ async-limiter@~1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
|
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
|
||||||
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
|
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
|
||||||
|
|
||||||
async-retry@^1.2.1:
|
async-retry@^1.2.1, async-retry@^1.3.1:
|
||||||
version "1.3.1"
|
version "1.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/async-retry/-/async-retry-1.3.1.tgz#139f31f8ddce50c0870b0ba558a6079684aaed55"
|
resolved "https://registry.yarnpkg.com/async-retry/-/async-retry-1.3.1.tgz#139f31f8ddce50c0870b0ba558a6079684aaed55"
|
||||||
integrity sha512-aiieFW/7h3hY0Bq5d+ktDBejxuwR78vRu9hDUdR8rNhSaQ29VzPL4AoIRG7D/c7tdenwOcKvgPM6tIxB3cB6HA==
|
integrity sha512-aiieFW/7h3hY0Bq5d+ktDBejxuwR78vRu9hDUdR8rNhSaQ29VzPL4AoIRG7D/c7tdenwOcKvgPM6tIxB3cB6HA==
|
||||||
|
|
Loading…
Reference in New Issue