node-redlock
node-redlock copied to clipboard
Submitting a value for the lock
I tried to submit this in a branch & PR but I keep getting access denied.
My request: Allow to submit a value for the lock in case the user wants it to have a specific value (which it can then monitor, for example).
My use case - I want to put my AWS InstanceId
as a value so I'd know which instance put the lock there, and if my instance enters a certain status (if it dies, for example), I could look up the keys and clear any that have the value of my instance id.
See screenshot
Or patch:
Index: src/index.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/index.ts b/src/index.ts
--- a/src/index.ts (revision 5dd9e281daae8f086ccb9284a9fc8709faf74a2a)
+++ b/src/index.ts (date 1685549192965)
@@ -297,13 +297,14 @@
public async acquire(
resources: string[],
duration: number,
- settings?: Partial<Settings>
+ settings?: Partial<Settings>,
+ lockValue?: string,
): Promise<Lock> {
if (Math.floor(duration) !== duration) {
throw new Error("Duration must be an integer value in milliseconds.");
}
- const value = this._random();
+ const value = typeof lockValue === 'undefined' ? this._random() : lockValue;
try {
const { attempts, start } = await this._execute(