@hvedinich/utils 0.0.54 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hvedinich/utils",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "utils module",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ const healthState = require('./healthState');
2
+ const runHealthCheck = require('./runHealthCheck');
3
+
4
+ module.exports = {
5
+ healthState,
6
+ runHealthCheck,
7
+ };
@@ -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
+ } ;