@oneuptime/common 7.0.3303 → 7.0.3309
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.
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
import { PingResult, createClient, ClickHouseClient } from "@clickhouse/client";
|
|
8
8
|
import DatabaseNotConnectedException from "Common/Types/Exception/DatabaseNotConnectedException";
|
|
9
9
|
import Sleep from "Common/Types/Sleep";
|
|
10
|
+
import API from "../../Utils/API";
|
|
11
|
+
import URL from "../../Types/API/URL";
|
|
12
|
+
import HTTPErrorResponse from "../../Types/API/HTTPErrorResponse";
|
|
13
|
+
import HTTPResponse from "../../Types/API/HTTPResponse";
|
|
14
|
+
import { JSONObject } from "../../Types/JSON";
|
|
10
15
|
|
|
11
16
|
export type ClickhouseClient = ClickHouseClient;
|
|
12
17
|
|
|
@@ -103,7 +108,18 @@ export default class ClickhouseDatabase {
|
|
|
103
108
|
logger.debug(
|
|
104
109
|
"Checking Clickhouse Connection Status - pinging clickhouse",
|
|
105
110
|
);
|
|
106
|
-
|
|
111
|
+
|
|
112
|
+
const dbUrl: string | undefined = this.getDatasourceOptions().url as
|
|
113
|
+
| string
|
|
114
|
+
| undefined;
|
|
115
|
+
|
|
116
|
+
if (!dbUrl) {
|
|
117
|
+
throw new DatabaseNotConnectedException("Clickhouse URL not found");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const result: HTTPErrorResponse | HTTPResponse<JSONObject> =
|
|
121
|
+
await API.get(URL.fromString(dbUrl.toString()));
|
|
122
|
+
|
|
107
123
|
logger.debug("Clickhouse Connection Status Result");
|
|
108
124
|
logger.debug(result);
|
|
109
125
|
|
|
@@ -113,13 +129,24 @@ export default class ClickhouseDatabase {
|
|
|
113
129
|
);
|
|
114
130
|
}
|
|
115
131
|
|
|
116
|
-
if (result
|
|
132
|
+
if (result instanceof HTTPErrorResponse) {
|
|
117
133
|
throw new DatabaseNotConnectedException(
|
|
118
134
|
"Clickhouse Database is not connected",
|
|
119
135
|
);
|
|
120
136
|
}
|
|
121
137
|
|
|
122
|
-
|
|
138
|
+
if (
|
|
139
|
+
result.data &&
|
|
140
|
+
((result.data as JSONObject)["data"] as string) &&
|
|
141
|
+
((result.data as JSONObject)["data"] as string).toString().trim() ===
|
|
142
|
+
"Ok."
|
|
143
|
+
) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
throw new DatabaseNotConnectedException(
|
|
148
|
+
"Clickhouse Database is not connected",
|
|
149
|
+
);
|
|
123
150
|
} catch (err) {
|
|
124
151
|
logger.error("Clickhouse Connection Lost");
|
|
125
152
|
logger.error(err);
|
|
@@ -3,6 +3,9 @@ import { dataSourceOptions, testDataSourceOptions, } from "./ClickhouseConfig";
|
|
|
3
3
|
import { createClient } from "@clickhouse/client";
|
|
4
4
|
import DatabaseNotConnectedException from "Common/Types/Exception/DatabaseNotConnectedException";
|
|
5
5
|
import Sleep from "Common/Types/Sleep";
|
|
6
|
+
import API from "../../Utils/API";
|
|
7
|
+
import URL from "../../Types/API/URL";
|
|
8
|
+
import HTTPErrorResponse from "../../Types/API/HTTPErrorResponse";
|
|
6
9
|
export default class ClickhouseDatabase {
|
|
7
10
|
getDatasourceOptions() {
|
|
8
11
|
return dataSourceOptions;
|
|
@@ -62,20 +65,29 @@ export default class ClickhouseDatabase {
|
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
async checkConnnectionStatus() {
|
|
65
|
-
var _a;
|
|
66
68
|
// Ping clickhouse to check if the connection is still alive
|
|
67
69
|
try {
|
|
68
70
|
logger.debug("Checking Clickhouse Connection Status - pinging clickhouse");
|
|
69
|
-
const
|
|
71
|
+
const dbUrl = this.getDatasourceOptions().url;
|
|
72
|
+
if (!dbUrl) {
|
|
73
|
+
throw new DatabaseNotConnectedException("Clickhouse URL not found");
|
|
74
|
+
}
|
|
75
|
+
const result = await API.get(URL.fromString(dbUrl.toString()));
|
|
70
76
|
logger.debug("Clickhouse Connection Status Result");
|
|
71
77
|
logger.debug(result);
|
|
72
78
|
if (!result) {
|
|
73
79
|
throw new DatabaseNotConnectedException("Clickhouse Database is not connected");
|
|
74
80
|
}
|
|
75
|
-
if (
|
|
81
|
+
if (result instanceof HTTPErrorResponse) {
|
|
76
82
|
throw new DatabaseNotConnectedException("Clickhouse Database is not connected");
|
|
77
83
|
}
|
|
78
|
-
|
|
84
|
+
if (result.data &&
|
|
85
|
+
result.data["data"] &&
|
|
86
|
+
result.data["data"].toString().trim() ===
|
|
87
|
+
"Ok.") {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
throw new DatabaseNotConnectedException("Clickhouse Database is not connected");
|
|
79
91
|
}
|
|
80
92
|
catch (err) {
|
|
81
93
|
logger.error("Clickhouse Connection Lost");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClickhouseDatabase.js","sourceRoot":"","sources":["../../../../Server/Infrastructure/ClickhouseDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAc,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAChF,OAAO,6BAA6B,MAAM,sDAAsD,CAAC;AACjG,OAAO,KAAK,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ClickhouseDatabase.js","sourceRoot":"","sources":["../../../../Server/Infrastructure/ClickhouseDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAc,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAChF,OAAO,6BAA6B,MAAM,sDAAsD,CAAC;AACjG,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,GAAG,MAAM,iBAAiB,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,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,6BAA6B,CACrC,sCAAsC,CACvC,CAAC;YACJ,CAAC;YAED,IAAI,MAAM,YAAY,iBAAiB,EAAE,CAAC;gBACxC,MAAM,IAAI,6BAA6B,CACrC,sCAAsC,CACvC,CAAC;YACJ,CAAC;YAED,IACE,MAAM,CAAC,IAAI;gBACT,MAAM,CAAC,IAAmB,CAAC,MAAM,CAAY;gBAC7C,MAAM,CAAC,IAAmB,CAAC,MAAM,CAAY,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;oBAC/D,KAAK,EACP,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,6BAA6B,CACrC,sCAAsC,CACvC,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAC3C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,qBAAqB,GAChC,IAAI,kBAAkB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneuptime/common",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3309",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"airtable": "^0.12.2",
|
|
78
78
|
"axios": "^1.7.2",
|
|
79
79
|
"bullmq": "^5.3.3",
|
|
80
|
-
"Common": "npm:@oneuptime/common@7.0.
|
|
80
|
+
"Common": "npm:@oneuptime/common@7.0.3309",
|
|
81
81
|
"cookie-parser": "^1.4.7",
|
|
82
82
|
"cors": "^2.8.5",
|
|
83
83
|
"cron-parser": "^4.8.1",
|