@mereb/shared-packages 0.0.7 → 0.0.11
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/dist/cache/redis.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type RedisClientType } from '@redis/client';
|
|
2
2
|
export interface RedisOptions {
|
|
3
3
|
url: string;
|
|
4
|
+
connectTimeoutMs?: number;
|
|
4
5
|
}
|
|
5
6
|
export declare function getRedisClient(options: RedisOptions): Promise<RedisClientType>;
|
|
6
7
|
export declare function disconnectRedis(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/cache/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/cache/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAQnE,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAiCD,wBAAsB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAepF;AAED,wBAAsB,eAAe,kBAKpC"}
|
package/dist/cache/redis.js
CHANGED
|
@@ -8,14 +8,52 @@ exports.disconnectRedis = disconnectRedis;
|
|
|
8
8
|
const client_1 = require("@redis/client");
|
|
9
9
|
const pino_1 = __importDefault(require("pino"));
|
|
10
10
|
const logger = (0, pino_1.default)({ name: 'redis' });
|
|
11
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = 5_000;
|
|
11
12
|
let client;
|
|
13
|
+
function withTimeout(promise, timeoutMs) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
reject(new Error(`Timed out connecting to Redis after ${timeoutMs}ms`));
|
|
17
|
+
}, timeoutMs);
|
|
18
|
+
promise
|
|
19
|
+
.then((value) => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
resolve(value);
|
|
22
|
+
})
|
|
23
|
+
.catch((error) => {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
reject(error);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function connectClient(instance, timeoutMs) {
|
|
30
|
+
try {
|
|
31
|
+
await withTimeout(instance.connect(), timeoutMs);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
try {
|
|
35
|
+
await instance.disconnect();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// ignore disconnect errors during cleanup
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
12
43
|
async function getRedisClient(options) {
|
|
13
44
|
if (!client) {
|
|
45
|
+
const timeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
14
46
|
client = (0, client_1.createClient)({ url: options.url });
|
|
15
47
|
client.on('error', (err) => {
|
|
16
48
|
logger.error({ err }, 'Redis connection error');
|
|
17
49
|
});
|
|
18
|
-
|
|
50
|
+
try {
|
|
51
|
+
await connectClient(client, timeoutMs);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
client = undefined;
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
19
57
|
}
|
|
20
58
|
return client;
|
|
21
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/observability/otel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/observability/otel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACtC;AAED,wBAAgB,aAAa,CAAC,EAC5B,WAAW,EACX,YAAY,EACZ,gBAAqB,EACtB,EAAE,UAAU,QA0BZ"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initTelemetry = initTelemetry;
|
|
4
4
|
const api_1 = require("@opentelemetry/api");
|
|
5
5
|
const resources_1 = require("@opentelemetry/resources");
|
|
6
|
-
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
7
6
|
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
8
7
|
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
9
8
|
const exporter_trace_otlp_grpc_1 = require("@opentelemetry/exporter-trace-otlp-grpc");
|
|
@@ -15,7 +14,7 @@ function initTelemetry({ serviceName, otlpEndpoint, instrumentations = [] }) {
|
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
16
|
const resource = new resources_1.Resource({
|
|
18
|
-
|
|
17
|
+
'service.name': serviceName
|
|
19
18
|
});
|
|
20
19
|
const provider = new sdk_trace_node_1.NodeTracerProvider({ resource });
|
|
21
20
|
if (otlpEndpoint) {
|