@alcalzone/jsonl-db
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -73,2 +73,4 @@ export interface JsonlDBOptions<V> { | ||
retries?: number; | ||
/** The start interval used for retries. Default: updateMs/2 */ | ||
retryMinTimeoutMs?: number; | ||
}>; | ||
@@ -75,0 +77,0 @@ /** |
@@ -108,5 +108,5 @@ "use strict"; | ||
if (options.lockfile) { | ||
const { directory, retries, staleMs = 10000, updateMs = staleMs / 2, } = options.lockfile; | ||
if (staleMs < 5000) { | ||
throw new Error("staleMs must be >= 5000"); | ||
const { directory, retries, staleMs = 10000, updateMs = staleMs / 2, retryMinTimeoutMs, } = options.lockfile; | ||
if (staleMs < 2000) { | ||
throw new Error("staleMs must be >= 2000"); | ||
} | ||
@@ -125,2 +125,5 @@ if (updateMs < 1000) { | ||
} | ||
if (retryMinTimeoutMs != undefined && retryMinTimeoutMs < 100) { | ||
throw new Error("retryMinTimeoutMs must be >= 100"); | ||
} | ||
if (options.lockfileDirectory != undefined && | ||
@@ -150,3 +153,3 @@ directory != undefined) { | ||
async open() { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e, _f; | ||
// Open the file for appending and reading | ||
@@ -157,2 +160,3 @@ await fs.ensureDir(path.dirname(this.filename)); | ||
retryOptions = { | ||
minTimeout: (_b = this.options.lockfile.retryMinTimeoutMs) !== null && _b !== void 0 ? _b : ((_c = this.options.lockfile.updateMs) !== null && _c !== void 0 ? _c : 2000) / 2, | ||
retries: this.options.lockfile.retries, | ||
@@ -171,5 +175,5 @@ factor: 1.25, | ||
? 100000 | ||
: /* istanbul ignore next - this is impossible to test */ (_b = this | ||
.options.lockfile) === null || _b === void 0 ? void 0 : _b.staleMs, | ||
update: (_c = this.options.lockfile) === null || _c === void 0 ? void 0 : _c.updateMs, | ||
: /* istanbul ignore next - this is impossible to test */ (_d = this | ||
.options.lockfile) === null || _d === void 0 ? void 0 : _d.staleMs, | ||
update: (_e = this.options.lockfile) === null || _e === void 0 ? void 0 : _e.updateMs, | ||
retries: retryOptions, | ||
@@ -249,3 +253,3 @@ onCompromised: /* istanbul ignore next */ () => { | ||
// If the DB should be compressed while opening, do it now | ||
if ((_d = this.options.autoCompress) === null || _d === void 0 ? void 0 : _d.onOpen) | ||
if ((_f = this.options.autoCompress) === null || _f === void 0 ? void 0 : _f.onOpen) | ||
await this.compress(); | ||
@@ -252,0 +256,0 @@ } |
{ | ||
"name": "@alcalzone/jsonl-db", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"description": "Simple JSONL-based key-value store", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
@@ -95,5 +95,6 @@ # jsonl-db | ||
| `directory` | - | Change where the lockfile is created, e.g. to put the lockfile into a `tmpfs`. By default the lockfile is created in the same directory as the DB file. If the directory does not exist, it will be created when opening the DB. | | ||
| `staleMs` | `10000` | Duration after which the lock is considered stale. Minimum: `5000` | | ||
| `staleMs` | `10000` | Duration after which the lock is considered stale. Minimum: `2000` | | ||
| `updateMs` | `staleMs/2` | The interval in which the lockfile's `mtime` will be updated. Range: `1000 ... staleMs/2` | | ||
| `retries` | `0` | How often to retry acquiring a lock before giving up. The retries progressively wait longer with an exponential backoff strategy. | | ||
| `retryMinTimeoutMs` | `updateMs/2` or `1000` | The start interval used for retries. Minimum: `100` | | ||
@@ -153,2 +154,6 @@ | ||
--> | ||
### 2.5.1 (2022-02-13) | ||
* Allow setting minimum retry timeout | ||
* Correct minimum value for the lockfile's stale timeout | ||
### 2.5.0 (2022-02-13) | ||
@@ -155,0 +160,0 @@ * Add the ability to control the lockfile's stale/update timeouts and retrying acquiring a lock |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
74829
926
250