Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting a value for the lock #278

Open
itayl2 opened this issue May 31, 2023 · 0 comments
Open

Submitting a value for the lock #278

itayl2 opened this issue May 31, 2023 · 0 comments

Comments

@itayl2
Copy link

itayl2 commented May 31, 2023

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
image

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(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant