@autofleet/node-common 1.1.26 → 1.1.27
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.
- package/package.json +5 -2
- package/settings/index.js +10 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/node-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"coverage": "jest --coverage --forceExit --runInBand",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://gitlab.com/AutoFleet/node-common#README",
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@google-cloud/logging-winston": "^0.9.0",
|
|
26
|
+
"@google-cloud/monitoring": "^0.6.0",
|
|
27
|
+
"@google-cloud/profiler": "^0.2.0",
|
|
25
28
|
"@google-cloud/pubsub": "^0.19.0",
|
|
26
29
|
"axios": "^0.18.0",
|
|
27
30
|
"axios-retry": "^3.1.0",
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
"portfinder": "^1.0.13",
|
|
36
39
|
"qs": "^6.5.2",
|
|
37
40
|
"timekeeper": "^2.1.2",
|
|
38
|
-
"winston": "^3.0.0
|
|
41
|
+
"winston": "^3.0.0",
|
|
39
42
|
"ws": "^5.2.1"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
package/settings/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const fiveMinutes = 60 * 5;
|
|
|
9
9
|
|
|
10
10
|
const findUrl = serviceUrl => serviceUrl ||
|
|
11
11
|
(process.env.SETTING_MS_SERVICE_HOST && process.env.SETTING_MS_SERVICE_HOST.length > 0 ? `http://${process.env.SETTING_MS_SERVICE_HOST}/` : undefined) ||
|
|
12
|
-
|
|
12
|
+
(process.env.NODE_ENV !== 'test' ? 'http://setting-ms.autofleet.io/' : 'http://localhost:9999/');
|
|
13
13
|
|
|
14
14
|
module.exports = class SettingsManager {
|
|
15
15
|
constructor({ serviceUrl, ttl = fiveMinutes } = {}) {
|
|
@@ -27,16 +27,16 @@ module.exports = class SettingsManager {
|
|
|
27
27
|
throw new Error('Can\'t get a key without defaultValue');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
if (process.env.NODE_ENV === 'test') {
|
|
31
|
-
return defaultValue;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
30
|
const cacheKey = `${key}_${JSON.stringify(labels)}`;
|
|
35
31
|
const cacheValue = this.settingsCache.get(cacheKey);
|
|
36
32
|
if (cacheValue !== undefined) {
|
|
37
33
|
return cacheValue;
|
|
38
34
|
}
|
|
39
35
|
|
|
36
|
+
if (process.env.NODE_ENV === 'test') {
|
|
37
|
+
return defaultValue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
40
|
let networkValue;
|
|
41
41
|
try {
|
|
42
42
|
const networkReponse = await this.network.get(`/api/v1/settings/get-setting/${key}`, {
|
|
@@ -55,6 +55,11 @@ module.exports = class SettingsManager {
|
|
|
55
55
|
return returnValue;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
setLocal(key, labels, value) {
|
|
59
|
+
const cacheKey = `${key}_${JSON.stringify(labels)}`;
|
|
60
|
+
this.settingsCache.set(cacheKey, value, this.ttl);
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
flush() {
|
|
59
64
|
return this.settingsCache.flushAll();
|
|
60
65
|
}
|