@contember/database
Advanced tools
Comparing version 0.9.1 to 0.9.2-alpha.0
@@ -8,3 +8,3 @@ "use strict"; | ||
minTimeout: 20, | ||
maxTimeout: 70, | ||
maxTimeout: 100, | ||
}; | ||
@@ -15,5 +15,9 @@ exports.retryTransaction = async (cb, options = {}) => { | ||
const minTimeout = (_a = options.minTimeout) !== null && _a !== void 0 ? _a : defaultOptions.minTimeout; | ||
const additionalTimeout = ((_b = options.maxTimeout) !== null && _b !== void 0 ? _b : defaultOptions.maxTimeout) - minTimeout; | ||
const maxAttempts = (_c = options.maxAttempts) !== null && _c !== void 0 ? _c : defaultOptions.maxAttempts; | ||
const timeout = async () => await new Promise(resolve => setTimeout(resolve, Math.round(minTimeout + Math.random() * additionalTimeout))); | ||
const maxAttempts = (_b = options.maxAttempts) !== null && _b !== void 0 ? _b : defaultOptions.maxAttempts; | ||
const additionalTimeout = (((_c = options.maxTimeout) !== null && _c !== void 0 ? _c : defaultOptions.maxTimeout) - minTimeout) / maxAttempts; | ||
const timeout = async (attempt) => { | ||
const timeout = Math.round(minTimeout + Math.random() * additionalTimeout * attempt); | ||
await new Promise(resolve => setTimeout(resolve, timeout)); | ||
return timeout; | ||
}; | ||
do { | ||
@@ -29,9 +33,9 @@ attempt++; | ||
if (attempt < maxAttempts) { | ||
const timeoutMs = await timeout(attempt); | ||
// eslint-disable-next-line no-console | ||
console.error('Serialization failure, retrying'); | ||
await timeout(); | ||
console.error(`RETRY: Serialization failure (attempt #${attempt}, retrying after ${timeoutMs}ms)`); | ||
} | ||
else { | ||
// eslint-disable-next-line no-console | ||
console.error('Serialization failure, aborting'); | ||
console.error(`ABORT: Serialization failure (attempt #${attempt})`); | ||
throw e; | ||
@@ -38,0 +42,0 @@ } |
{ | ||
"name": "@contember/database", | ||
"version": "0.9.1", | ||
"version": "0.9.2-alpha.0", | ||
"license": "Apache-2.0", | ||
@@ -11,7 +11,7 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/queryable": "^0.9.1", | ||
"@contember/queryable": "^0.9.2-alpha.0", | ||
"pg": "^7.17.1" | ||
}, | ||
"devDependencies": { | ||
"@contember/database-tester": "^0.9.1", | ||
"@contember/database-tester": "^0.9.2-alpha.0", | ||
"@types/jasmine": "^3.5.10", | ||
@@ -18,0 +18,0 @@ "@types/node": "^14.6.4", |
@@ -12,3 +12,3 @@ import { SerializationFailureError } from '../client' | ||
minTimeout: 20, | ||
maxTimeout: 70, | ||
maxTimeout: 100, | ||
} | ||
@@ -22,6 +22,9 @@ | ||
const minTimeout = options.minTimeout ?? defaultOptions.minTimeout | ||
const additionalTimeout = (options.maxTimeout ?? defaultOptions.maxTimeout) - minTimeout | ||
const maxAttempts = options.maxAttempts ?? defaultOptions.maxAttempts | ||
const timeout = async () => | ||
await new Promise(resolve => setTimeout(resolve, Math.round(minTimeout + Math.random() * additionalTimeout))) | ||
const additionalTimeout = ((options.maxTimeout ?? defaultOptions.maxTimeout) - minTimeout) / maxAttempts | ||
const timeout = async (attempt: number) => { | ||
const timeout = Math.round(minTimeout + Math.random() * additionalTimeout * attempt) | ||
await new Promise(resolve => setTimeout(resolve, timeout)) | ||
return timeout | ||
} | ||
@@ -37,8 +40,8 @@ do { | ||
if (attempt < maxAttempts) { | ||
const timeoutMs = await timeout(attempt) | ||
// eslint-disable-next-line no-console | ||
console.error('Serialization failure, retrying') | ||
await timeout() | ||
console.error(`RETRY: Serialization failure (attempt #${attempt}, retrying after ${timeoutMs}ms)`) | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.error('Serialization failure, aborting') | ||
console.error(`ABORT: Serialization failure (attempt #${attempt})`) | ||
throw e | ||
@@ -45,0 +48,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1324439
5015