@dignetwork/dig-sdk 0.0.1-alpha.108 → 0.0.1-alpha.109
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.
|
@@ -6,7 +6,8 @@ export declare class StoreInfoCacheUpdater {
|
|
|
6
6
|
private releaseLock;
|
|
7
7
|
private constructor();
|
|
8
8
|
static initInstance(): StoreInfoCacheUpdater;
|
|
9
|
-
private
|
|
9
|
+
private scheduleNextUpdate;
|
|
10
|
+
private checkAndUpdateCache;
|
|
10
11
|
private updateCache;
|
|
11
12
|
private setupExitHandlers;
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreInfoCacheUpdater.d.ts","sourceRoot":"","sources":["../../src/blockchain/StoreInfoCacheUpdater.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StoreInfoCacheUpdater.d.ts","sourceRoot":"","sources":["../../src/blockchain/StoreInfoCacheUpdater.ts"],"names":[],"mappings":"AAQA,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwB;IAC/C,OAAO,CAAC,cAAc,CAInB;IACH,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAsC;IAEzD,OAAO;WAcO,YAAY,IAAI,qBAAqB;IAOnD,OAAO,CAAC,kBAAkB;YAIZ,mBAAmB;YAkBnB,WAAW;IA4FzB,OAAO,CAAC,iBAAiB;CAsB1B"}
|
|
@@ -24,13 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.StoreInfoCacheUpdater = void 0;
|
|
27
|
-
const timers_1 = require("timers");
|
|
28
27
|
const FullNodePeer_1 = require("./FullNodePeer");
|
|
29
28
|
const utils_1 = require("../utils");
|
|
30
29
|
const DataStoreSerializer_1 = require("./DataStoreSerializer");
|
|
31
30
|
const utils_2 = require("../utils");
|
|
32
31
|
const lockfile = __importStar(require("proper-lockfile"));
|
|
33
|
-
const fs = __importStar(require("fs"));
|
|
34
32
|
const path = __importStar(require("path"));
|
|
35
33
|
const utils_3 = require("../utils");
|
|
36
34
|
class StoreInfoCacheUpdater {
|
|
@@ -40,7 +38,8 @@ class StoreInfoCacheUpdater {
|
|
|
40
38
|
this.updateInterval = updateIntervalInMinutes * 60 * 1000; // Convert minutes to milliseconds
|
|
41
39
|
// Construct lock file path using the path module
|
|
42
40
|
this.lockFilePath = path.join(utils_3.DIG_FOLDER_PATH, 'store-info-cache.lock');
|
|
43
|
-
|
|
41
|
+
// Start the cache updater using setTimeout
|
|
42
|
+
this.scheduleNextUpdate();
|
|
44
43
|
// Set up process exit handlers for cleanup
|
|
45
44
|
this.setupExitHandlers();
|
|
46
45
|
}
|
|
@@ -50,22 +49,33 @@ class StoreInfoCacheUpdater {
|
|
|
50
49
|
}
|
|
51
50
|
return StoreInfoCacheUpdater.instance;
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
(
|
|
52
|
+
scheduleNextUpdate() {
|
|
53
|
+
setTimeout(() => this.checkAndUpdateCache(), this.updateInterval);
|
|
55
54
|
}
|
|
56
|
-
async
|
|
55
|
+
async checkAndUpdateCache() {
|
|
57
56
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const isLocked = await lockfile.check(this.lockFilePath, {
|
|
58
|
+
stale: this.updateInterval,
|
|
59
|
+
});
|
|
60
|
+
if (!isLocked) {
|
|
61
|
+
await this.updateCache();
|
|
61
62
|
}
|
|
62
|
-
//
|
|
63
|
+
// Else, lock is held; skip update without logging
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error("Error checking lockfile:", error);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
// Schedule the next update regardless of whether we updated or not
|
|
70
|
+
this.scheduleNextUpdate();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async updateCache() {
|
|
74
|
+
try {
|
|
75
|
+
// Attempt to acquire the lock
|
|
63
76
|
const release = await lockfile.lock(this.lockFilePath, {
|
|
64
77
|
retries: {
|
|
65
|
-
retries:
|
|
66
|
-
factor: 2,
|
|
67
|
-
minTimeout: 100,
|
|
68
|
-
maxTimeout: 1000,
|
|
78
|
+
retries: 0, // No retries since we already checked the lock
|
|
69
79
|
},
|
|
70
80
|
stale: this.updateInterval, // Lock expires after the update interval
|
|
71
81
|
});
|
|
@@ -103,7 +113,7 @@ class StoreInfoCacheUpdater {
|
|
|
103
113
|
}
|
|
104
114
|
catch (error) {
|
|
105
115
|
console.error(`Failed to update cache for storeId ${storeId}:`, error);
|
|
106
|
-
//
|
|
116
|
+
// Continue with the next storeId
|
|
107
117
|
}
|
|
108
118
|
}
|
|
109
119
|
}
|
|
@@ -114,7 +124,12 @@ class StoreInfoCacheUpdater {
|
|
|
114
124
|
}
|
|
115
125
|
}
|
|
116
126
|
catch (error) {
|
|
117
|
-
|
|
127
|
+
if (error.code === 'ELOCKED') {
|
|
128
|
+
// Another process acquired the lock; skip without logging
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.error("Failed to update store cache:", error);
|
|
132
|
+
}
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
setupExitHandlers() {
|