@hvedinich/utils 0.0.53 → 0.0.55
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
CHANGED
package/src/constants/index.js
CHANGED
|
@@ -12,6 +12,15 @@ const guestCtx = {
|
|
|
12
12
|
uid: 'guest-user',
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
const healthCheckStatuses = {
|
|
16
|
+
INIT_VIBER_WEBHOOK: 'INIT_VIBER_WEBHOOK',
|
|
17
|
+
INIT_TELEGRAM_WEBHOOK: 'INIT_TELEGRAM_WEBHOOK',
|
|
18
|
+
SUBSCRIBE_MQ: 'SUBSCRIBE_MQ',
|
|
19
|
+
INIT_QUEUE: 'INIT_QUEUE',
|
|
20
|
+
TELEGRAM_HEALTH_CHECK: 'TELEGRAM_HEALTH_CHECK',
|
|
21
|
+
DB_CONNECT: 'DB_CONNECT',
|
|
22
|
+
};
|
|
23
|
+
|
|
15
24
|
const auth = {
|
|
16
25
|
permission: {
|
|
17
26
|
SYSTEM_USER,
|
|
@@ -21,6 +30,7 @@ const auth = {
|
|
|
21
30
|
};
|
|
22
31
|
|
|
23
32
|
module.exports = {
|
|
33
|
+
healthCheckStatuses,
|
|
24
34
|
serverCtx,
|
|
25
35
|
guestCtx,
|
|
26
36
|
token,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const status = {
|
|
2
|
+
status: true,
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const checkIsAlive = () => Object.values(status).every(e => e === true);
|
|
6
|
+
|
|
7
|
+
const setStatus = (key, value) => {
|
|
8
|
+
status[key] = !!value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
checkIsAlive,
|
|
13
|
+
setStatus,
|
|
14
|
+
status,
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
module.exports = async (config) => {
|
|
4
|
+
const url = `${config.host}:${config.port}/_status`;
|
|
5
|
+
let data;
|
|
6
|
+
try {
|
|
7
|
+
data = await axios.get(url);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
const errorMessage = JSON.stringify(err?.stack || err).slice(0, 300);
|
|
10
|
+
await axios.post(
|
|
11
|
+
`https://api.telegram.org/bot${config.serviceTelegram.token}/sendMessage?chat_id=${config.serviceTelegram.healthChecksChatId}&text=${config.serviceName} does not work, err: ${errorMessage}`,
|
|
12
|
+
);
|
|
13
|
+
return process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
if (data?.data?.healthy) {
|
|
16
|
+
return process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
await axios.post(
|
|
19
|
+
`https://api.telegram.org/bot${config.serviceTelegram.token}/sendMessage?chat_id=${config.serviceTelegram.healthChecksChatId}&text=${config.serviceName} does not work, status: ${JSON.stringify(
|
|
20
|
+
data?.data?.status,
|
|
21
|
+
)}`,
|
|
22
|
+
);
|
|
23
|
+
return process.exit(1);
|
|
24
|
+
} ;
|
package/src/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const mappers = require('./mappers');
|
|
|
5
5
|
const common = require('./common');
|
|
6
6
|
const permission = require('./permission');
|
|
7
7
|
const config = require('./config');
|
|
8
|
+
const healthCheck = require('./healthCheck');
|
|
8
9
|
|
|
9
10
|
module.exports = {
|
|
10
11
|
context,
|
|
@@ -14,4 +15,5 @@ module.exports = {
|
|
|
14
15
|
permission,
|
|
15
16
|
config,
|
|
16
17
|
common,
|
|
18
|
+
healthCheck
|
|
17
19
|
};
|