@johnmmackey/ms-utils 4.2.0 → 4.3.0
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/lib/config.js +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ sendmail(
|
|
|
47
47
|
* uses ```dotenv``` to load a .env file in the current working directory into the environment
|
|
48
48
|
* pushes all items loaded from etcd into the environment.
|
|
49
49
|
|
|
50
|
-
The order of precedence:
|
|
50
|
+
The order of precedence: .env > .env > externally set environment
|
|
51
51
|
|
|
52
52
|
## Future
|
|
53
53
|
* Add local queueing for log events when AMQP is not operative.
|
package/lib/config.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { Etcd3 } = require('etcd3');
|
|
4
4
|
const dotenv = require('dotenv');
|
|
5
|
-
const client = new Etcd3({ hosts: process.env.ETCD_URI || 'http://localhost:2379' });
|
|
6
|
-
|
|
7
5
|
|
|
8
6
|
// helpers
|
|
9
7
|
// https://stackoverflow.com/questions/42429590/retry-on-javascript-promise-reject-a-limited-number-of-times-or-until-success
|
|
@@ -12,7 +10,7 @@ Promise.retry = (cont, fn, delay) => fn().catch(err => cont > 0 ? Promise.wait(d
|
|
|
12
10
|
|
|
13
11
|
var config = {};
|
|
14
12
|
|
|
15
|
-
async function tryLoad(serviceName) {
|
|
13
|
+
async function tryLoad(client, serviceName) {
|
|
16
14
|
let scoped = await client
|
|
17
15
|
.namespace(`${process.env.CONFIG_SET || ''}/${serviceName}/`)
|
|
18
16
|
.getAll()
|
|
@@ -29,10 +27,17 @@ async function load(serviceName) {
|
|
|
29
27
|
// load any .env file that may be present into the environment
|
|
30
28
|
dotenv.config({ override: true });
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
const client = new Etcd3({ hosts: process.env.ETCD_URI || 'http://localhost:2379' });
|
|
31
|
+
|
|
32
|
+
await Promise.retry(10, tryLoad.bind(this, client, serviceName), 5000);
|
|
33
33
|
|
|
34
34
|
// as a side-effect, load these into process.env
|
|
35
35
|
dotenv.populate(process.env, config, { override: true });
|
|
36
|
+
|
|
37
|
+
// load any .env file that may be present into the environment
|
|
38
|
+
// again to override
|
|
39
|
+
// why? the first one may be necessary to find an etcd server...
|
|
40
|
+
dotenv.config({ override: true });
|
|
36
41
|
return config;
|
|
37
42
|
}
|
|
38
43
|
|