@johnmmackey/ms-utils 4.2.0 → 4.2.1
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 +3 -0
- package/lib/config.js +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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,7 +27,9 @@ 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 });
|