Comparing version 0.10.4 to 0.10.5
@@ -0,1 +1,8 @@ | ||
## [0.10.5](https://github.com/VaclavObornik/mongodash/compare/v0.10.4...v0.10.5) (2021-07-30) | ||
### Bug Fixes | ||
* stabilized tests and max wait time for withLock ([86c6e2d](https://github.com/VaclavObornik/mongodash/commit/86c6e2d27d153c609586731776cc5a0a8ae37d81)) | ||
## [0.10.4](https://github.com/VaclavObornik/mongodash/compare/v0.10.3...v0.10.4) (2021-07-26) | ||
@@ -2,0 +9,0 @@ |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -12,6 +12,6 @@ * | ||
// import * as _debug from 'debug'; | ||
const exponential_backoff_1 = require("exponential-backoff"); | ||
const mongodb_1 = require("mongodb"); | ||
const createContinuousLock_1 = require("./createContinuousLock"); | ||
const getCollection_1 = require("./getCollection"); | ||
const lodash_1 = require("lodash"); | ||
// const debug = _debug('mongodash:withLock'); | ||
@@ -39,2 +39,3 @@ let onError; | ||
const stringKey = `${key}`; | ||
const maxDate = new Date(Date.now() + maxWaitForLock); | ||
const collection = await getLockerCollection(); | ||
@@ -58,23 +59,26 @@ const releaseLock = () => collection.deleteOne({ _id: stringKey, lockId }); | ||
}; | ||
const maxDate = new Date(Date.now() + maxWaitForLock); | ||
const maxDelay = Math.max(startingDelay, maxWaitForLock / 3); | ||
const timeMultiple = Math.random() * (3 - 1) + 1; // Random from 1 to 3 | ||
await exponential_backoff_1.backOff(acquireLock, { | ||
delayFirstAttempt: false, | ||
jitter: 'none', | ||
numOfAttempts: Number.MAX_SAFE_INTEGER, | ||
startingDelay, | ||
timeMultiple, | ||
maxDelay, | ||
retry: (err /*, n*/) => { | ||
const possibleNextRetry = new Date(Date.now() + maxDelay); | ||
// debug(`resolving retry ${n}, timeMultiple ${timeMultiple}, maxDate ${maxDate.toLocaleTimeString()}.${maxDate.getMilliseconds()}, possibleNextRetry ${possibleNextRetry.toLocaleTimeString()}.${possibleNextRetry.getMilliseconds()}`); | ||
return err.message === lockAcquiredMessage && possibleNextRetry < maxDate; | ||
}, | ||
}); | ||
for (let n = 0; n < Number.MAX_SAFE_INTEGER; n++) { | ||
try { | ||
await acquireLock(); | ||
break; | ||
} | ||
catch (err) { | ||
const randomMultiplier = lodash_1.random(1, 1.2, true); | ||
const waitTime = Math.min(2 ** n * randomMultiplier * startingDelay, maxDelay); | ||
const nextTime = new Date(Date.now() + waitTime); | ||
// debug(`wait time ${waitTime} for ${n}`); | ||
if (err.message === lockAcquiredMessage && nextTime < maxDate) { | ||
await new Promise((resolve) => setTimeout(resolve, waitTime)); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
// todo solve the "any" | ||
const stopContinuousLock = createContinuousLock_1.createContinuousLock(collection, stringKey, expirationKey, expireIn, onError); | ||
let value; | ||
try { | ||
// intentional await because of finally block | ||
return await callback(); | ||
value = await callback(); | ||
} | ||
@@ -84,4 +88,5 @@ finally { | ||
} | ||
return value; | ||
} | ||
exports.withLock = withLock; | ||
//# sourceMappingURL=withLock.js.map |
/**! | ||
* mongodash v0.10.4 | ||
* mongodash v0.10.5 | ||
* https://github.com/VaclavObornik/mongodash.git | ||
@@ -4,0 +4,0 @@ * |
{ | ||
"name": "mongodash", | ||
"version": "0.10.4", | ||
"version": "0.10.5", | ||
"description": "An utility library delivering super-useful and super-simple tools using MongoDB", | ||
@@ -31,3 +31,2 @@ "main": "dist/lib/index.js", | ||
"debug": "^4.3.1", | ||
"exponential-backoff": "^3.1.0", | ||
"parse-duration": "^1.0.0" | ||
@@ -34,0 +33,0 @@ }, |
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
53594
4
723
- Removedexponential-backoff@^3.1.0
- Removedexponential-backoff@3.1.1(transitive)