@medusajs/locking-redis 0.0.2-snapshot-20241013171145 → 0.0.2-snapshot-20241016062841

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,20 @@
1
1
  import { ILockingProvider } from "@medusajs/types";
2
+ import { RedisCacheModuleOptions } from "../types";
2
3
  import { Redis } from "ioredis";
3
- declare const RedisLockingProvider_base: import("@medusajs/framework/utils").MedusaServiceReturnType<import("@medusajs/framework/utils").ModelConfigurationsToConfigTemplate<{}>>;
4
- export declare class RedisLockingProvider extends RedisLockingProvider_base implements ILockingProvider {
4
+ export declare class RedisLockingProvider implements ILockingProvider {
5
5
  static identifier: string;
6
6
  protected redisClient: Redis & {
7
7
  acquireLock: (key: string, ownerId: string, ttl: number, awaitQueue?: boolean) => Promise<number>;
8
8
  releaseLock: (key: string, ownerId: string) => Promise<number>;
9
9
  };
10
10
  protected keyNamePrefix: string;
11
+ protected waitLockingTimeout: number;
12
+ protected defaultRetryInterval: number;
13
+ protected maximumRetryInterval: number;
11
14
  constructor({ redisClient, prefix }: {
12
15
  redisClient: any;
13
16
  prefix: any;
14
- });
17
+ }, options: RedisCacheModuleOptions);
15
18
  private getKeyName;
16
19
  execute<T>(keys: string | string[], job: () => Promise<T>, args?: {
17
20
  timeout?: number;
@@ -36,5 +39,4 @@ export declare class RedisLockingProvider extends RedisLockingProvider_base impl
36
39
  }): Promise<void>;
37
40
  private getTimeout;
38
41
  }
39
- export {};
40
42
  //# sourceMappingURL=redis-lock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis-lock.d.ts","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;;AAG/B,qBAAa,oBACX,SAAQ,yBACR,YAAW,gBAAgB;IAE3B,MAAM,CAAC,UAAU,SAAkB;IAEnC,SAAS,CAAC,WAAW,EAAE,KAAK,GAAG;QAC7B,W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O,CAAC,CAAC,CAAC;IA8BP,OAAO,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,GACA,OAAO,CAAC,IAAI,CAAC;IAIV,QAAQ,CACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,EACD,iBAAiB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GACzC,OAAO,CAAC,IAAI,CAAC;IAqDV,OAAO,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACxB,GACA,OAAO,CAAC,OAAO,CAAC;IAeb,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAwCrD,UAAU;CAUzB"}
@@ -3,11 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RedisLockingProvider = void 0;
4
4
  const utils_1 = require("@medusajs/framework/utils");
5
5
  const promises_1 = require("node:timers/promises");
6
- class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
7
- constructor({ redisClient, prefix }) {
8
- super(...arguments);
6
+ class RedisLockingProvider {
7
+ constructor({ redisClient, prefix }, options) {
8
+ this.waitLockingTimeout = 5;
9
+ this.defaultRetryInterval = 5;
10
+ this.maximumRetryInterval = 200;
9
11
  this.redisClient = redisClient;
10
12
  this.keyNamePrefix = prefix ?? "medusa_lock:";
13
+ if (!isNaN(+options?.waitLockingTimeout)) {
14
+ this.waitLockingTimeout = +options.waitLockingTimeout;
15
+ }
16
+ if (!isNaN(+options?.defaultRetryInterval)) {
17
+ this.defaultRetryInterval = +options.defaultRetryInterval;
18
+ }
19
+ if (!isNaN(+options?.maximumRetryInterval)) {
20
+ this.maximumRetryInterval = +options.maximumRetryInterval;
21
+ }
11
22
  // Define the custom command for acquiring locks
12
23
  this.redisClient.defineCommand("acquireLock", {
13
24
  numberOfKeys: 1,
@@ -17,22 +28,36 @@ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
17
28
  local ttl = tonumber(ARGV[2])
18
29
  local awaitQueue = ARGV[3] == 'true'
19
30
 
20
- local setResult = redis.call('SET', key, ownerId, 'EX', ttl, 'NX')
31
+ local setArgs = {key, ownerId, 'NX'}
32
+ if ttl > 0 then
33
+ table.insert(setArgs, 'EX')
34
+ table.insert(setArgs, ttl)
35
+ end
36
+
37
+ local setResult = redis.call('SET', unpack(setArgs))
21
38
 
22
39
  if setResult then
23
- return 1
24
- elseif not awaitQueue then
25
- -- Key already exists; retrieve the current ownerId
26
- local currentOwnerId = redis.call('GET', key)
27
- if currentOwnerId == ownerId then
28
- redis.call('SET', key, ownerId, 'EX', ttl, 'XX')
29
40
  return 1
30
- else
31
- return 0
32
- end
41
+ elseif not awaitQueue then
42
+ -- Key already exists; retrieve the current ownerId
43
+ local currentOwnerId = redis.call('GET', key)
44
+ if currentOwnerId == '*' then
45
+ return 0
46
+ elseif currentOwnerId == ownerId then
47
+ setArgs = {key, ownerId, 'XX'}
48
+ if ttl > 0 then
49
+ table.insert(setArgs, 'EX')
50
+ table.insert(setArgs, ttl)
51
+ end
52
+ redis.call('SET', unpack(setArgs))
53
+ return 1
54
+ else
55
+ return 0
56
+ end
33
57
  else
34
- return 0
58
+ return 0
35
59
  end
60
+
36
61
  `,
37
62
  });
38
63
  // Define the custom command for releasing locks
@@ -54,7 +79,7 @@ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
54
79
  return `${this.keyNamePrefix}${key}`;
55
80
  }
56
81
  async execute(keys, job, args) {
57
- const timeout = Math.max(args?.timeout ?? 5, 1);
82
+ const timeout = Math.max(args?.timeout ?? this.waitLockingTimeout, 1);
58
83
  const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
59
84
  const cancellationToken = { cancelled: false };
60
85
  const promises = [];
@@ -63,6 +88,7 @@ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
63
88
  }
64
89
  promises.push(this.acquire_(keys, {
65
90
  awaitQueue: true,
91
+ expire: args?.timeout ? timeoutSeconds : 0,
66
92
  }, cancellationToken));
67
93
  await Promise.race(promises);
68
94
  try {
@@ -77,35 +103,39 @@ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
77
103
  }
78
104
  async acquire_(keys, args, cancellationToken) {
79
105
  keys = Array.isArray(keys) ? keys : [keys];
80
- const timeout = Math.max(args?.expire ?? 5, 1);
106
+ const timeout = Math.max(args?.expire ?? this.waitLockingTimeout, 1);
81
107
  const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
108
+ let retryTimes = 0;
82
109
  const ownerId = args?.ownerId ?? "*";
83
110
  const awaitQueue = args?.awaitQueue ?? false;
84
111
  const acquirePromises = keys.map(async (key) => {
112
+ const errMessage = `Failed to acquire lock for key "${key}"`;
85
113
  const keyName = this.getKeyName(key);
86
114
  const acquireLock = async () => {
87
115
  while (true) {
88
116
  if (cancellationToken?.cancelled) {
89
- return;
117
+ throw new Error(errMessage);
90
118
  }
91
- const result = await this.redisClient.acquireLock(keyName, ownerId, timeoutSeconds, awaitQueue);
119
+ const result = await this.redisClient.acquireLock(keyName, ownerId, args?.expire ? timeoutSeconds : 0, awaitQueue);
92
120
  if (result === 1) {
93
121
  break;
94
122
  }
95
123
  else {
96
124
  if (awaitQueue) {
97
125
  // Wait for a short period before retrying
98
- await (0, promises_1.setTimeout)(100);
126
+ await (0, promises_1.setTimeout)(Math.min(this.defaultRetryInterval +
127
+ (retryTimes / 10) * this.defaultRetryInterval, this.maximumRetryInterval));
128
+ retryTimes++;
99
129
  }
100
130
  else {
101
- throw new Error(`Failed to acquire lock for key "${key}"`);
131
+ throw new Error(errMessage);
102
132
  }
103
133
  }
104
134
  }
105
135
  };
106
136
  await acquireLock();
107
137
  });
108
- await Promise.all(acquirePromises);
138
+ await (0, utils_1.promiseAll)(acquirePromises);
109
139
  }
110
140
  async release(keys, args) {
111
141
  const ownerId = args?.ownerId ?? "*";
@@ -115,7 +145,7 @@ class RedisLockingProvider extends (0, utils_1.MedusaService)({}) {
115
145
  const result = await this.redisClient.releaseLock(keyName, ownerId);
116
146
  return result === 1;
117
147
  });
118
- const results = await Promise.all(releasePromises);
148
+ const results = await (0, utils_1.promiseAll)(releasePromises);
119
149
  return results.every((released) => released);
120
150
  }
121
151
  async releaseAll(args) {
@@ -1 +1 @@
1
- {"version":3,"file":"redis-lock.js","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAGzD,mDAAiD;AAEjD,MAAa,oBACX,SAAQ,IAAA,qBAAa,EAAC,EAAE,CAAC;IAgBzB,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE;QACjC,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,IAAI,cAAc,CAAA;QAE7C,gDAAgD;QAChD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE;YAC5C,YAAY,EAAE,CAAC;YACf,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;OAsBJ;SACF,CAAC,CAAA;QAEF,gDAAgD;QAChD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE;YAC5C,YAAY,EAAE,CAAC;YACf,GAAG,EAAE;;;;;;;;;OASJ;SACF,CAAC,CAAA;IACJ,CAAC;IAEO,UAAU,CAAC,GAAW;QAC5B,OAAO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AU,GAAG,eAAe,AAAlB,CAAkB"}
@@ -20,5 +20,20 @@ export type RedisCacheModuleOptions = {
20
20
  * @default `medusa_lock:`
21
21
  */
22
22
  namespace?: string;
23
+ /**
24
+ * Time to wait for lock (in seconds)
25
+ * @default 5
26
+ */
27
+ waitLockingTimeout?: number;
28
+ /**
29
+ * Default retry interval (in milliseconds)
30
+ * @default 5
31
+ */
32
+ defaultRetryInterval?: number;
33
+ /**
34
+ * Maximum retry interval (in milliseconds)
35
+ * @default 200
36
+ */
37
+ maximumRetryInterval?: number;
23
38
  };
24
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/locking-redis",
3
- "version": "0.0.2-snapshot-20241013171145",
3
+ "version": "0.0.2-snapshot-20241016062841",
4
4
  "description": "Redis Lock for Medusa",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "author": "Medusa",
21
21
  "license": "MIT",
22
22
  "devDependencies": {
23
- "@medusajs/framework": "0.0.2-snapshot-20241013171145",
23
+ "@medusajs/framework": "0.0.2-snapshot-20241016062841",
24
24
  "@swc/core": "^1.7.28",
25
25
  "@swc/jest": "^0.2.36",
26
26
  "jest": "^29.7.0",
@@ -28,7 +28,7 @@
28
28
  "typescript": "^5.6.2"
29
29
  },
30
30
  "peerDependencies": {
31
- "@medusajs/framework": "0.0.2-snapshot-20241013171145"
31
+ "@medusajs/framework": "0.0.2-snapshot-20241016062841"
32
32
  },
33
33
  "dependencies": {
34
34
  "ioredis": "^5.4.1"