@clonegod/ttd-bsc-common 1.0.42 → 1.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,9 +39,6 @@ class SimpleRedisClient {
39
39
  });
40
40
  (0, dist_1.log_info)(`try acquireLock: lock_key=${lock_key}, lock_value=${lock_value}, expireSeconds=${expireSeconds}, result=${result}`);
41
41
  const success = result === 'OK';
42
- if (success) {
43
- (0, dist_1.log_info)(`acquire lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
44
- }
45
42
  return success;
46
43
  });
47
44
  }
@@ -60,17 +57,11 @@ class SimpleRedisClient {
60
57
  arguments: [lock_value]
61
58
  });
62
59
  const success = Number(result) === 1;
63
- if (success) {
64
- (0, dist_1.log_info)(`release lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
65
- }
66
- else {
67
- (0, dist_1.log_info)(`release lock failed: lock_key=${lock_key}, lock_value=${lock_value}, maybe expired or locked by other process`);
68
- }
69
60
  return success;
70
61
  });
71
62
  }
72
63
  withLock(lock_identifier_1, callback_1) {
73
- return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 2000) {
64
+ return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 100) {
74
65
  const lock_key = this.getLockKey(lock_identifier);
75
66
  const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
76
67
  let retries = 0;
@@ -93,8 +84,10 @@ class SimpleRedisClient {
93
84
  finally {
94
85
  if (acquired) {
95
86
  const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
96
- yield (0, dist_1.sleep)(release_delay);
97
- yield this.releaseLock(lock_key, lock_value);
87
+ if (release_delay > 0) {
88
+ yield (0, dist_1.sleep)(release_delay);
89
+ }
90
+ this.releaseLock(lock_key, lock_value);
98
91
  (0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, get lock take ${get_lock_time - first_try_time}ms, release_delay=${release_delay}ms, hold lock ${Date.now() - get_lock_time}ms`);
99
92
  }
100
93
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",