@hvedinich/db 1.0.0 → 1.0.2
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.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: Publish DB
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
update-version-publish-and-release:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v2
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 18
|
|
20
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm ci
|
|
24
|
+
|
|
25
|
+
- name: Update patch version
|
|
26
|
+
run: |
|
|
27
|
+
npm version patch --no-git-tag-version
|
|
28
|
+
git config --local user.email "rooolik@gmail.com"
|
|
29
|
+
git config --local user.name "hvedinich"
|
|
30
|
+
git commit -am "Update version to $(node -p "require('./package.json').version")"
|
|
31
|
+
git push
|
|
32
|
+
|
|
33
|
+
- name: Publish to npm
|
|
34
|
+
uses: JS-DevTools/npm-publish@v3
|
|
35
|
+
with:
|
|
36
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
37
|
+
|
|
38
|
+
- name: Read Changelog
|
|
39
|
+
id: changelog
|
|
40
|
+
run: echo "::set-output name=body::$(cat CHANGELOG.md)"
|
|
41
|
+
|
|
42
|
+
- name: Get package.json version
|
|
43
|
+
id: package_version
|
|
44
|
+
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
|
|
45
|
+
shell: bash
|
|
46
|
+
|
|
47
|
+
- name: Set the version in the env
|
|
48
|
+
run: echo "VERSION=${{ steps.package_version.outputs.version }}" >> $GITHUB_ENV
|
|
49
|
+
|
|
50
|
+
- name: Create release
|
|
51
|
+
env:
|
|
52
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
53
|
+
run: |
|
|
54
|
+
gh release create "$VERSION" \
|
|
55
|
+
--repo="$GITHUB_REPOSITORY" \
|
|
56
|
+
--title="${GITHUB_REPOSITORY#*/} ${VERSION#v}" \
|
|
57
|
+
--generate-notes
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -3,8 +3,10 @@ const migration = require('./migration');
|
|
|
3
3
|
|
|
4
4
|
const init = ({ config, setStatus }) => {
|
|
5
5
|
const db = mongoose.connection;
|
|
6
|
+
|
|
7
|
+
const maxCount = 30;
|
|
6
8
|
let retry = 0;
|
|
7
|
-
|
|
9
|
+
let timerId;
|
|
8
10
|
|
|
9
11
|
const state = { connected: false };
|
|
10
12
|
const opt = {
|
|
@@ -20,23 +22,17 @@ const init = ({ config, setStatus }) => {
|
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
db.on('disconnected', async () => {
|
|
23
|
-
console.log(`Can not connect to mongo retry: ${retry}`);
|
|
24
25
|
state.connected = false;
|
|
25
|
-
|
|
26
|
-
retry
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
console.log(`retry error: ${err?.message || JSON.stringify(err)}`);
|
|
26
|
+
timerId = setInterval(() => {
|
|
27
|
+
retry += 1;
|
|
28
|
+
console.log(`Can not connect to mongo retry: ${retry}`);
|
|
29
|
+
if (retry >= maxCount) {
|
|
30
|
+
clearInterval(timerId);
|
|
31
|
+
timerId = undefined;
|
|
32
|
+
retry = 0;
|
|
33
|
+
setStatus(false);
|
|
35
34
|
}
|
|
36
|
-
}
|
|
37
|
-
if (retry >= maxCount) {
|
|
38
|
-
setStatus(false);
|
|
39
|
-
}
|
|
35
|
+
}, 1000);
|
|
40
36
|
});
|
|
41
37
|
|
|
42
38
|
db.on('error', () => {
|
|
@@ -44,8 +40,13 @@ const init = ({ config, setStatus }) => {
|
|
|
44
40
|
mongoose.disconnect();
|
|
45
41
|
});
|
|
46
42
|
db.on('open', () => {
|
|
47
|
-
console.log(
|
|
43
|
+
console.log('Mongo is connected');
|
|
48
44
|
state.connected = true;
|
|
45
|
+
if (timerId) {
|
|
46
|
+
clearInterval(timerId);
|
|
47
|
+
timerId = undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
49
50
|
setStatus(true);
|
|
50
51
|
retry = 0;
|
|
51
52
|
});
|