@clonegod/ttd-bsc-common 1.0.16 → 1.0.17

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.
@@ -75,6 +75,8 @@ class SimpleRedisClient {
75
75
  const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
76
76
  let retries = 0;
77
77
  let acquired = false;
78
+ let first_try_time = Date.now();
79
+ let get_lock_time = 0;
78
80
  try {
79
81
  while (retries < this.lockMaxRetries) {
80
82
  acquired = yield this.acquireLock(lock_key, lock_value);
@@ -86,12 +88,18 @@ class SimpleRedisClient {
86
88
  if (!acquired) {
87
89
  throw new Error(`acquire lock failed: lock_key=${lock_key}, lock_value=${lock_value}, after ${this.lockMaxRetries} retries, maybe locked by other process`);
88
90
  }
91
+ get_lock_time = Date.now();
89
92
  return yield callback();
90
93
  }
91
94
  finally {
92
95
  if (acquired) {
93
- yield (0, dist_1.sleep)(parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms)));
96
+ const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
97
+ yield (0, dist_1.sleep)(release_delay);
94
98
  yield this.releaseLock(lock_key, lock_value);
99
+ (0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, lock_value=${lock_value}, get lock take ${get_lock_time - first_try_time}ms, release_delay=${release_delay}ms, hold lock ${Date.now() - get_lock_time}ms`);
100
+ }
101
+ else {
102
+ (0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, lock_value=${lock_value}, after ${this.lockMaxRetries} retries, took ${Date.now() - first_try_time}ms`);
95
103
  }
96
104
  }
97
105
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",