pp-command-bus 1.3.1 → 1.4.0
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/README.md +89 -8
- package/dist/command-bus/command-bus.spec.js +4 -0
- package/dist/command-bus/command-bus.spec.js.map +1 -1
- package/dist/command-bus/index.d.ts +10 -0
- package/dist/command-bus/index.js +53 -11
- package/dist/command-bus/index.js.map +1 -1
- package/dist/command-bus/job/job-processor.d.ts +3 -1
- package/dist/command-bus/job/job-processor.js +17 -1
- package/dist/command-bus/job/job-processor.js.map +1 -1
- package/dist/command-bus/job/job-processor.spec.js +142 -1
- package/dist/command-bus/job/job-processor.spec.js.map +1 -1
- package/dist/command-bus/rpc/index.d.ts +3 -0
- package/dist/command-bus/rpc/index.js +4 -1
- package/dist/command-bus/rpc/index.js.map +1 -1
- package/dist/command-bus/rpc/rpc-coordinator.d.ts +27 -1
- package/dist/command-bus/rpc/rpc-coordinator.js +131 -3
- package/dist/command-bus/rpc/rpc-coordinator.js.map +1 -1
- package/dist/command-bus/rpc/rpc-coordinator.spec.js +228 -21
- package/dist/command-bus/rpc/rpc-coordinator.spec.js.map +1 -1
- package/dist/command-bus/rpc/rpc-job-cancellation.service.d.ts +82 -0
- package/dist/command-bus/rpc/rpc-job-cancellation.service.js +180 -0
- package/dist/command-bus/rpc/rpc-job-cancellation.service.js.map +1 -0
- package/dist/command-bus/rpc/rpc-job-cancellation.service.spec.d.ts +1 -0
- package/dist/command-bus/rpc/rpc-job-cancellation.service.spec.js +286 -0
- package/dist/command-bus/rpc/rpc-job-cancellation.service.spec.js.map +1 -0
- package/dist/command-bus/types/index.d.ts +4 -0
- package/dist/command-bus/worker/worker-orchestrator.js +3 -1
- package/dist/command-bus/worker/worker-orchestrator.js.map +1 -1
- package/dist/examples/rpc-resilience.demo.d.ts +11 -0
- package/dist/examples/rpc-resilience.demo.js +235 -0
- package/dist/examples/rpc-resilience.demo.js.map +1 -0
- package/dist/pp-command-bus-1.4.0.tgz +0 -0
- package/dist/shared/config/base-config.d.ts +11 -0
- package/dist/shared/config/base-config.js +14 -0
- package/dist/shared/config/base-config.js.map +1 -1
- package/dist/shared/config/base-config.spec.js +102 -16
- package/dist/shared/config/base-config.spec.js.map +1 -1
- package/dist/shared/redis/index.d.ts +6 -0
- package/dist/shared/redis/index.js +15 -0
- package/dist/shared/redis/index.js.map +1 -0
- package/dist/shared/redis/redis-connection-factory.d.ts +66 -0
- package/dist/shared/redis/redis-connection-factory.js +113 -0
- package/dist/shared/redis/redis-connection-factory.js.map +1 -0
- package/dist/shared/redis/redis-error-formatter.d.ts +30 -0
- package/dist/shared/redis/redis-error-formatter.js +56 -0
- package/dist/shared/redis/redis-error-formatter.js.map +1 -0
- package/package.json +1 -1
- package/dist/pp-command-bus-1.3.1.tgz +0 -0
|
Binary file
|
|
@@ -18,9 +18,20 @@ export default class BaseConfig {
|
|
|
18
18
|
* Logger do użycia (domyślnie wbudowany Logger z console)
|
|
19
19
|
*/
|
|
20
20
|
logger: ILogger;
|
|
21
|
+
/**
|
|
22
|
+
* Opóźnienie między próbami reconnect do Redis w milisekundach
|
|
23
|
+
* Domyślnie 5000ms (5 sekund)
|
|
24
|
+
*/
|
|
25
|
+
redisRetryDelay: number;
|
|
26
|
+
/**
|
|
27
|
+
* Maksymalna liczba prób reconnect do Redis
|
|
28
|
+
* 0 = nieskończoność (domyślnie)
|
|
29
|
+
*/
|
|
30
|
+
redisMaxRetries: number;
|
|
21
31
|
constructor(params?: Partial<BaseConfig>);
|
|
22
32
|
/**
|
|
23
33
|
* Zwraca opcje połączenia Redis na podstawie URL
|
|
34
|
+
* Zawiera retryStrategy z konfiguracją reconnect
|
|
24
35
|
*/
|
|
25
36
|
getRedisOptions(): ConnectionOptions;
|
|
26
37
|
/**
|
|
@@ -16,6 +16,9 @@ class BaseConfig {
|
|
|
16
16
|
this.logLevel = initialLogLevel;
|
|
17
17
|
// Utwórz logger z odpowiednim poziomem
|
|
18
18
|
this.logger = new logger_1.Logger(console, this.logLevel);
|
|
19
|
+
// Ustaw opcje reconnect Redis
|
|
20
|
+
this.redisRetryDelay = this.parseIntWithDefault(process.env.REDIS_RETRY_DELAY, 5000);
|
|
21
|
+
this.redisMaxRetries = this.parseIntWithDefault(process.env.REDIS_MAX_RETRIES, 0);
|
|
19
22
|
if (params) {
|
|
20
23
|
// Zapamię tај logLevel przed merge params
|
|
21
24
|
const originalLogLevel = this.logLevel;
|
|
@@ -33,13 +36,24 @@ class BaseConfig {
|
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* Zwraca opcje połączenia Redis na podstawie URL
|
|
39
|
+
* Zawiera retryStrategy z konfiguracją reconnect
|
|
36
40
|
*/
|
|
37
41
|
getRedisOptions() {
|
|
38
42
|
try {
|
|
39
43
|
const url = new URL(this.redisUrl);
|
|
44
|
+
// Przechwytujemy wartości dla closure w retryStrategy
|
|
45
|
+
const retryDelay = this.redisRetryDelay;
|
|
46
|
+
const maxRetries = this.redisMaxRetries;
|
|
40
47
|
const options = {
|
|
41
48
|
host: url.hostname,
|
|
42
49
|
port: parseInt(url.port, 10) || 6379,
|
|
50
|
+
retryStrategy: (times) => {
|
|
51
|
+
// Max retries (0 = nieskończoność)
|
|
52
|
+
if (maxRetries > 0 && times > maxRetries) {
|
|
53
|
+
return null; // Stop reconnecting
|
|
54
|
+
}
|
|
55
|
+
return retryDelay;
|
|
56
|
+
},
|
|
43
57
|
};
|
|
44
58
|
if (url.username) {
|
|
45
59
|
options.username = url.username;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-config.js","sourceRoot":"","sources":["../../../src/shared/config/base-config.ts"],"names":[],"mappings":";;AAGA,8CAA2C;AAE3C;;GAEG;AACH,MAAqB,UAAU;
|
|
1
|
+
{"version":3,"file":"base-config.js","sourceRoot":"","sources":["../../../src/shared/config/base-config.ts"],"names":[],"mappings":";;AAGA,8CAA2C;AAE3C;;GAEG;AACH,MAAqB,UAAU;IA6B7B,YAAmB,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C7B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,EAA6B,CAAC;QAClE,OAAO,gCACF,OAAO,KACV,oBAAoB,EAAE,IAAI,GACN,CAAC;IACzB,CAAC;IAED;;OAEG;IACO,QAAQ;QAChB,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAAC,WAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED;;OAEG;IACO,mBAAmB,CAAC,KAAyB,EAAE,YAAoB;QAC3E,IAAI,CAAC,KAAK;YAAE,OAAO,YAAY,CAAC;QAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,KAAyB,EAAE,YAAqB;QAC7E,IAAI,CAAC,KAAK;YAAE,OAAO,YAAY,CAAC;QAChC,OAAO,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG,CAAC;IACzD,CAAC;CACF;AAhJD,6BAgJC"}
|
|
@@ -22,6 +22,8 @@ describe('BaseConfig', () => {
|
|
|
22
22
|
expect(config.redisUrl).toBe('redis://localhost:6379');
|
|
23
23
|
expect(config.logger).toBeInstanceOf(logger_1.Logger);
|
|
24
24
|
expect(config.logLevel).toBe('log');
|
|
25
|
+
expect(config.redisRetryDelay).toBe(5000);
|
|
26
|
+
expect(config.redisMaxRetries).toBe(0);
|
|
25
27
|
});
|
|
26
28
|
it('powinno wczytać konfigurację ze zmiennych środowiskowych', () => {
|
|
27
29
|
// Given
|
|
@@ -58,13 +60,12 @@ describe('BaseConfig', () => {
|
|
|
58
60
|
// When
|
|
59
61
|
const options = config.getRedisOptions();
|
|
60
62
|
// Then
|
|
61
|
-
expect(options).
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
63
|
+
expect(options.host).toBe('dragonfly.example.com');
|
|
64
|
+
expect(options.port).toBe(6380);
|
|
65
|
+
expect(options.username).toBe('user');
|
|
66
|
+
expect(options.password).toBe('pass');
|
|
67
|
+
expect(options.db).toBe(0);
|
|
68
|
+
expect(options.retryStrategy).toBeInstanceOf(Function);
|
|
68
69
|
});
|
|
69
70
|
it('powinno obsłużyć URL bez autoryzacji', () => {
|
|
70
71
|
// Given
|
|
@@ -74,10 +75,11 @@ describe('BaseConfig', () => {
|
|
|
74
75
|
// When
|
|
75
76
|
const options = config.getRedisOptions();
|
|
76
77
|
// Then
|
|
77
|
-
expect(options).
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
expect(options.host).toBe('localhost');
|
|
79
|
+
expect(options.port).toBe(6379);
|
|
80
|
+
expect(options.username).toBeUndefined();
|
|
81
|
+
expect(options.password).toBeUndefined();
|
|
82
|
+
expect(options.retryStrategy).toBeInstanceOf(Function);
|
|
81
83
|
});
|
|
82
84
|
it('powinno obsłużyć URL z bazą danych ale bez autoryzacji', () => {
|
|
83
85
|
// Given
|
|
@@ -87,11 +89,10 @@ describe('BaseConfig', () => {
|
|
|
87
89
|
// When
|
|
88
90
|
const options = config.getRedisOptions();
|
|
89
91
|
// Then
|
|
90
|
-
expect(options).
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
92
|
+
expect(options.host).toBe('localhost');
|
|
93
|
+
expect(options.port).toBe(6379);
|
|
94
|
+
expect(options.db).toBe(2);
|
|
95
|
+
expect(options.retryStrategy).toBeInstanceOf(Function);
|
|
95
96
|
});
|
|
96
97
|
it('powinno obsłużyć nieprawidłowy URL podczas tworzenia konfiguracji', () => {
|
|
97
98
|
// When & Then
|
|
@@ -100,6 +101,91 @@ describe('BaseConfig', () => {
|
|
|
100
101
|
})).toThrow('Invalid Redis URL');
|
|
101
102
|
});
|
|
102
103
|
});
|
|
104
|
+
describe('retryStrategy', () => {
|
|
105
|
+
it('powinno używać domyślnego opóźnienia 5000ms', () => {
|
|
106
|
+
// Given
|
|
107
|
+
const config = new base_config_1.default();
|
|
108
|
+
const options = config.getRedisOptions();
|
|
109
|
+
const retryStrategy = options.retryStrategy;
|
|
110
|
+
// When
|
|
111
|
+
const delay = retryStrategy(1);
|
|
112
|
+
// Then
|
|
113
|
+
expect(delay).toBe(5000);
|
|
114
|
+
});
|
|
115
|
+
it('powinno używać konfigurowalnego opóźnienia z env', () => {
|
|
116
|
+
// Given
|
|
117
|
+
process.env.REDIS_RETRY_DELAY = '10000';
|
|
118
|
+
const config = new base_config_1.default();
|
|
119
|
+
const options = config.getRedisOptions();
|
|
120
|
+
const retryStrategy = options.retryStrategy;
|
|
121
|
+
// When
|
|
122
|
+
const delay = retryStrategy(1);
|
|
123
|
+
// Then
|
|
124
|
+
expect(delay).toBe(10000);
|
|
125
|
+
});
|
|
126
|
+
it('powinno używać konfigurowalnego opóźnienia z parametrów', () => {
|
|
127
|
+
// Given
|
|
128
|
+
const config = new base_config_1.default({
|
|
129
|
+
redisRetryDelay: 3000,
|
|
130
|
+
});
|
|
131
|
+
const options = config.getRedisOptions();
|
|
132
|
+
const retryStrategy = options.retryStrategy;
|
|
133
|
+
// When
|
|
134
|
+
const delay = retryStrategy(1);
|
|
135
|
+
// Then
|
|
136
|
+
expect(delay).toBe(3000);
|
|
137
|
+
});
|
|
138
|
+
it('powinno zwracać stałe opóźnienie niezależnie od liczby prób', () => {
|
|
139
|
+
// Given
|
|
140
|
+
const config = new base_config_1.default({
|
|
141
|
+
redisRetryDelay: 5000,
|
|
142
|
+
});
|
|
143
|
+
const options = config.getRedisOptions();
|
|
144
|
+
const retryStrategy = options.retryStrategy;
|
|
145
|
+
// When & Then - stałe 5000ms dla wszystkich prób
|
|
146
|
+
expect(retryStrategy(1)).toBe(5000);
|
|
147
|
+
expect(retryStrategy(5)).toBe(5000);
|
|
148
|
+
expect(retryStrategy(10)).toBe(5000);
|
|
149
|
+
expect(retryStrategy(100)).toBe(5000);
|
|
150
|
+
});
|
|
151
|
+
it('powinno zatrzymać reconnect po przekroczeniu max retries', () => {
|
|
152
|
+
// Given
|
|
153
|
+
const config = new base_config_1.default({
|
|
154
|
+
redisRetryDelay: 5000,
|
|
155
|
+
redisMaxRetries: 3,
|
|
156
|
+
});
|
|
157
|
+
const options = config.getRedisOptions();
|
|
158
|
+
const retryStrategy = options.retryStrategy;
|
|
159
|
+
// When & Then
|
|
160
|
+
expect(retryStrategy(1)).toBe(5000);
|
|
161
|
+
expect(retryStrategy(2)).toBe(5000);
|
|
162
|
+
expect(retryStrategy(3)).toBe(5000);
|
|
163
|
+
expect(retryStrategy(4)).toBeNull(); // Przekroczono max
|
|
164
|
+
});
|
|
165
|
+
it('powinno używać konfigurowalnego max retries z env', () => {
|
|
166
|
+
// Given
|
|
167
|
+
process.env.REDIS_MAX_RETRIES = '5';
|
|
168
|
+
const config = new base_config_1.default();
|
|
169
|
+
const options = config.getRedisOptions();
|
|
170
|
+
const retryStrategy = options.retryStrategy;
|
|
171
|
+
// When & Then
|
|
172
|
+
expect(retryStrategy(5)).toBe(5000);
|
|
173
|
+
expect(retryStrategy(6)).toBeNull(); // Przekroczono max
|
|
174
|
+
});
|
|
175
|
+
it('powinno kontynuować reconnect w nieskończoność gdy max retries = 0', () => {
|
|
176
|
+
// Given
|
|
177
|
+
const config = new base_config_1.default({
|
|
178
|
+
redisRetryDelay: 5000,
|
|
179
|
+
redisMaxRetries: 0, // 0 = nieskończoność
|
|
180
|
+
});
|
|
181
|
+
const options = config.getRedisOptions();
|
|
182
|
+
const retryStrategy = options.retryStrategy;
|
|
183
|
+
// When & Then - nigdy nie zwraca null
|
|
184
|
+
expect(retryStrategy(1)).toBe(5000);
|
|
185
|
+
expect(retryStrategy(100)).toBe(5000);
|
|
186
|
+
expect(retryStrategy(1000)).toBe(5000);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
103
189
|
describe('walidacja', () => {
|
|
104
190
|
it('powinno zwalidować konfigurację przy tworzeniu', () => {
|
|
105
191
|
// Given
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-config.spec.js","sourceRoot":"","sources":["../../../src/shared/config/base-config.spec.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AAEvC,8CAA2C;AAE3C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhC,UAAU,CAAC,GAAG,EAAE;QACd,iCAAiC;QACjC,OAAO,CAAC,GAAG,qBAAQ,WAAW,CAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,OAAO;YACP,MAAM,MAAM,GAAG,IAAI,qBAAU,EAAE,CAAC;YAEhC,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,eAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"base-config.spec.js","sourceRoot":"","sources":["../../../src/shared/config/base-config.spec.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AAEvC,8CAA2C;AAE3C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhC,UAAU,CAAC,GAAG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C,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,QAAQ;YACR,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,oBAAoB,CAAC;YAE7C,cAAc;YACd,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,qBAAU,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,QAAQ;YACR,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,WAAW,CAAC;YAEpC,cAAc;YACd,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,qBAAU,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moduł Redis - eksporty publiczne
|
|
3
|
+
*/
|
|
4
|
+
export { default as RedisConnectionFactory } from './redis-connection-factory';
|
|
5
|
+
export type { RedisConnectionOptions } from './redis-connection-factory';
|
|
6
|
+
export { formatRedisError, getErrorCode } from './redis-error-formatter';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Moduł Redis - eksporty publiczne
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getErrorCode = exports.formatRedisError = exports.RedisConnectionFactory = void 0;
|
|
10
|
+
var redis_connection_factory_1 = require("./redis-connection-factory");
|
|
11
|
+
Object.defineProperty(exports, "RedisConnectionFactory", { enumerable: true, get: function () { return __importDefault(redis_connection_factory_1).default; } });
|
|
12
|
+
var redis_error_formatter_1 = require("./redis-error-formatter");
|
|
13
|
+
Object.defineProperty(exports, "formatRedisError", { enumerable: true, get: function () { return redis_error_formatter_1.formatRedisError; } });
|
|
14
|
+
Object.defineProperty(exports, "getErrorCode", { enumerable: true, get: function () { return redis_error_formatter_1.getErrorCode; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/redis/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,uEAA+E;AAAtE,mJAAA,OAAO,OAA0B;AAE1C,iEAAyE;AAAhE,yHAAA,gBAAgB,OAAA;AAAE,qHAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fabryka połączeń Redis z wbudowaną obsługą błędów i eventów
|
|
3
|
+
* Zgodna z SRP - odpowiada tylko za tworzenie i konfigurację połączeń
|
|
4
|
+
*/
|
|
5
|
+
import { Redis } from 'ioredis';
|
|
6
|
+
import type { ILogger } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Opcje połączenia Redis kompatybilne z ioredis
|
|
9
|
+
* BullMQ ConnectionOptions są kompatybilne z podstawowymi opcjami ioredis
|
|
10
|
+
*/
|
|
11
|
+
export interface RedisConnectionOptions {
|
|
12
|
+
host?: string;
|
|
13
|
+
port?: number;
|
|
14
|
+
username?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
db?: number;
|
|
17
|
+
maxRetriesPerRequest?: number | null;
|
|
18
|
+
/**
|
|
19
|
+
* Strategia ponownych prób połączenia
|
|
20
|
+
* Zwraca opóźnienie w ms lub null aby przerwać reconnect
|
|
21
|
+
*/
|
|
22
|
+
retryStrategy?: (times: number) => number | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fabryka połączeń Redis
|
|
26
|
+
*
|
|
27
|
+
* Zapewnia:
|
|
28
|
+
* - Tworzenie połączeń z pełną obsługą eventów (error, close, reconnecting, connect)
|
|
29
|
+
* - Poprawne formatowanie błędów (w tym AggregateError)
|
|
30
|
+
* - Logowanie stanu połączenia
|
|
31
|
+
* - Wariant dla workerów BullMQ (maxRetriesPerRequest: null)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const factory = new RedisConnectionFactory(logger);
|
|
35
|
+
* const connection = factory.create(options, 'QueueManager');
|
|
36
|
+
* const workerConnection = factory.createForWorker(options, 'Worker');
|
|
37
|
+
*/
|
|
38
|
+
export default class RedisConnectionFactory {
|
|
39
|
+
private readonly logger;
|
|
40
|
+
constructor(logger: ILogger);
|
|
41
|
+
/**
|
|
42
|
+
* Tworzy połączenie Redis z pełną obsługą eventów
|
|
43
|
+
*
|
|
44
|
+
* @param options - Opcje połączenia Redis
|
|
45
|
+
* @param name - Nazwa połączenia dla logów (np. 'QueueManager', 'RpcCoordinator')
|
|
46
|
+
* @returns Skonfigurowane połączenie Redis
|
|
47
|
+
*/
|
|
48
|
+
create(options: RedisConnectionOptions, name: string): Redis;
|
|
49
|
+
/**
|
|
50
|
+
* Tworzy połączenie Redis dla workerów BullMQ
|
|
51
|
+
* Dodaje maxRetriesPerRequest: null wymagane przez BullMQ dla blocking operations
|
|
52
|
+
*
|
|
53
|
+
* @param options - Opcje połączenia Redis
|
|
54
|
+
* @param name - Nazwa połączenia dla logów
|
|
55
|
+
* @returns Skonfigurowane połączenie Redis dla workera
|
|
56
|
+
*/
|
|
57
|
+
createForWorker(options: RedisConnectionOptions, name: string): Redis;
|
|
58
|
+
/**
|
|
59
|
+
* Konfiguruje handlery eventów dla połączenia Redis
|
|
60
|
+
* Zapobiega [ioredis] Unhandled error event
|
|
61
|
+
*
|
|
62
|
+
* @param connection - Połączenie Redis
|
|
63
|
+
* @param name - Nazwa połączenia dla logów
|
|
64
|
+
*/
|
|
65
|
+
private setupEventHandlers;
|
|
66
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fabryka połączeń Redis z wbudowaną obsługą błędów i eventów
|
|
4
|
+
* Zgodna z SRP - odpowiada tylko za tworzenie i konfigurację połączeń
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const ioredis_1 = require("ioredis");
|
|
8
|
+
const redis_error_formatter_1 = require("./redis-error-formatter");
|
|
9
|
+
/**
|
|
10
|
+
* Fabryka połączeń Redis
|
|
11
|
+
*
|
|
12
|
+
* Zapewnia:
|
|
13
|
+
* - Tworzenie połączeń z pełną obsługą eventów (error, close, reconnecting, connect)
|
|
14
|
+
* - Poprawne formatowanie błędów (w tym AggregateError)
|
|
15
|
+
* - Logowanie stanu połączenia
|
|
16
|
+
* - Wariant dla workerów BullMQ (maxRetriesPerRequest: null)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const factory = new RedisConnectionFactory(logger);
|
|
20
|
+
* const connection = factory.create(options, 'QueueManager');
|
|
21
|
+
* const workerConnection = factory.createForWorker(options, 'Worker');
|
|
22
|
+
*/
|
|
23
|
+
class RedisConnectionFactory {
|
|
24
|
+
constructor(logger) {
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tworzy połączenie Redis z pełną obsługą eventów
|
|
29
|
+
*
|
|
30
|
+
* @param options - Opcje połączenia Redis
|
|
31
|
+
* @param name - Nazwa połączenia dla logów (np. 'QueueManager', 'RpcCoordinator')
|
|
32
|
+
* @returns Skonfigurowane połączenie Redis
|
|
33
|
+
*/
|
|
34
|
+
create(options, name) {
|
|
35
|
+
const connection = new ioredis_1.Redis(options);
|
|
36
|
+
this.setupEventHandlers(connection, name);
|
|
37
|
+
return connection;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tworzy połączenie Redis dla workerów BullMQ
|
|
41
|
+
* Dodaje maxRetriesPerRequest: null wymagane przez BullMQ dla blocking operations
|
|
42
|
+
*
|
|
43
|
+
* @param options - Opcje połączenia Redis
|
|
44
|
+
* @param name - Nazwa połączenia dla logów
|
|
45
|
+
* @returns Skonfigurowane połączenie Redis dla workera
|
|
46
|
+
*/
|
|
47
|
+
createForWorker(options, name) {
|
|
48
|
+
const workerOptions = Object.assign(Object.assign({}, options), { maxRetriesPerRequest: null });
|
|
49
|
+
return this.create(workerOptions, name);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Konfiguruje handlery eventów dla połączenia Redis
|
|
53
|
+
* Zapobiega [ioredis] Unhandled error event
|
|
54
|
+
*
|
|
55
|
+
* @param connection - Połączenie Redis
|
|
56
|
+
* @param name - Nazwa połączenia dla logów
|
|
57
|
+
*/
|
|
58
|
+
setupEventHandlers(connection, name) {
|
|
59
|
+
// Flaga do śledzenia czy to reconnect (dla logowania na poziomie INFO)
|
|
60
|
+
let isReconnecting = false;
|
|
61
|
+
// Handler błędów - WYMAGANY aby uniknąć "Unhandled error event"
|
|
62
|
+
connection.on('error', (error) => {
|
|
63
|
+
this.logger.error(`Błąd połączenia Redis (${name})`, {
|
|
64
|
+
connectionName: name,
|
|
65
|
+
error: (0, redis_error_formatter_1.formatRedisError)(error),
|
|
66
|
+
errorCode: (0, redis_error_formatter_1.getErrorCode)(error),
|
|
67
|
+
timestamp: new Date().toISOString(),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
// Handler zamknięcia połączenia
|
|
71
|
+
connection.on('close', () => {
|
|
72
|
+
this.logger.warn(`Połączenie Redis zamknięte (${name})`, {
|
|
73
|
+
connectionName: name,
|
|
74
|
+
timestamp: new Date().toISOString(),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
// Handler ponownego łączenia - ustawia flagę dla logu INFO przy ready
|
|
78
|
+
connection.on('reconnecting', () => {
|
|
79
|
+
isReconnecting = true;
|
|
80
|
+
this.logger.log(`Ponowne łączenie z Redis (${name})`, {
|
|
81
|
+
connectionName: name,
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
// Handler nawiązania połączenia
|
|
86
|
+
connection.on('connect', () => {
|
|
87
|
+
this.logger.debug(`Połączono z Redis (${name})`, {
|
|
88
|
+
connectionName: name,
|
|
89
|
+
timestamp: new Date().toISOString(),
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
// Handler gotowości (po SELECT database)
|
|
93
|
+
// Po reconnect loguje na poziomie INFO, pierwsze połączenie na DEBUG
|
|
94
|
+
connection.on('ready', () => {
|
|
95
|
+
if (isReconnecting) {
|
|
96
|
+
this.logger.log(`Ponownie połączono z Redis (${name})`, {
|
|
97
|
+
connectionName: name,
|
|
98
|
+
reconnected: true,
|
|
99
|
+
timestamp: new Date().toISOString(),
|
|
100
|
+
});
|
|
101
|
+
isReconnecting = false;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.logger.debug(`Redis gotowy (${name})`, {
|
|
105
|
+
connectionName: name,
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.default = RedisConnectionFactory;
|
|
113
|
+
//# sourceMappingURL=redis-connection-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-connection-factory.js","sourceRoot":"","sources":["../../../src/shared/redis/redis-connection-factory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,qCAAmD;AAEnD,mEAAyE;AAoBzE;;;;;;;;;;;;;GAaG;AACH,MAAqB,sBAAsB;IACzC,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD;;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
+
* Formatuje błąd Redis do czytelnego stringa
|
|
7
|
+
* Obsługuje AggregateError który ma puste message ale zawiera errors[]
|
|
8
|
+
*
|
|
9
|
+
* @param error - Błąd do sformatowania
|
|
10
|
+
* @returns Sformatowany tekst błędu
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Zwykły błąd
|
|
14
|
+
* formatRedisError(new Error('Connection refused'))
|
|
15
|
+
* // => 'Connection refused'
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // AggregateError (np. przy próbie połączenia z IPv4 i IPv6)
|
|
19
|
+
* formatRedisError(aggregateError)
|
|
20
|
+
* // => 'AggregateError: connect ECONNREFUSED ::1:6379 (Error); connect ECONNREFUSED 127.0.0.1:6379 (Error)'
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatRedisError(error: Error): string;
|
|
23
|
+
/**
|
|
24
|
+
* Wyciąga kod błędu z obiektu Error (jeśli istnieje)
|
|
25
|
+
* Przydatne dla błędów Redis które zawierają kod jak ECONNREFUSED
|
|
26
|
+
*
|
|
27
|
+
* @param error - Błąd do sprawdzenia
|
|
28
|
+
* @returns Kod błędu lub undefined
|
|
29
|
+
*/
|
|
30
|
+
export declare function getErrorCode(error: Error): string | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Moduł formatowania błędów Redis
|
|
4
|
+
* Odpowiada za czytelne formatowanie błędów, w tym AggregateError
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.formatRedisError = formatRedisError;
|
|
8
|
+
exports.getErrorCode = getErrorCode;
|
|
9
|
+
/**
|
|
10
|
+
* Sprawdza czy błąd jest typu AggregateError
|
|
11
|
+
* @param error - Błąd do sprawdzenia
|
|
12
|
+
*/
|
|
13
|
+
function isAggregateError(error) {
|
|
14
|
+
return error.name === 'AggregateError' && 'errors' in error;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Formatuje błąd Redis do czytelnego stringa
|
|
18
|
+
* Obsługuje AggregateError który ma puste message ale zawiera errors[]
|
|
19
|
+
*
|
|
20
|
+
* @param error - Błąd do sformatowania
|
|
21
|
+
* @returns Sformatowany tekst błędu
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Zwykły błąd
|
|
25
|
+
* formatRedisError(new Error('Connection refused'))
|
|
26
|
+
* // => 'Connection refused'
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // AggregateError (np. przy próbie połączenia z IPv4 i IPv6)
|
|
30
|
+
* formatRedisError(aggregateError)
|
|
31
|
+
* // => 'AggregateError: connect ECONNREFUSED ::1:6379 (Error); connect ECONNREFUSED 127.0.0.1:6379 (Error)'
|
|
32
|
+
*/
|
|
33
|
+
function formatRedisError(error) {
|
|
34
|
+
// AggregateError ma puste message, ale zawiera tablicę errors
|
|
35
|
+
if (isAggregateError(error)) {
|
|
36
|
+
const errorMessages = error.errors
|
|
37
|
+
.map((err) => `${err.message} (${err.name})`)
|
|
38
|
+
.join('; ');
|
|
39
|
+
return `AggregateError: ${errorMessages}`;
|
|
40
|
+
}
|
|
41
|
+
return error.message || error.name || 'Nieznany błąd Redis';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wyciąga kod błędu z obiektu Error (jeśli istnieje)
|
|
45
|
+
* Przydatne dla błędów Redis które zawierają kod jak ECONNREFUSED
|
|
46
|
+
*
|
|
47
|
+
* @param error - Błąd do sprawdzenia
|
|
48
|
+
* @returns Kod błędu lub undefined
|
|
49
|
+
*/
|
|
50
|
+
function getErrorCode(error) {
|
|
51
|
+
if ('code' in error && typeof error.code === 'string') {
|
|
52
|
+
return error.code;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=redis-error-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-error-formatter.js","sourceRoot":"","sources":["../../../src/shared/redis/redis-error-formatter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmCH,4CAUC;AASD,oCAKC;AAjDD;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAAY;IACpC,OAAO,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAAC,KAAY;IAC3C,8DAA8D;IAC9D,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,GAAU,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;aACnD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,mBAAmB,aAAa,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,IAAI,qBAAqB,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,KAAY;IACvC,IAAI,MAAM,IAAI,KAAK,IAAI,OAAQ,KAAmC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrF,OAAQ,KAAkC,CAAC,IAAI,CAAC;IAClD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pp-command-bus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Distributed Command Bus library supporting RPC and job queuing with BullMQ for Redis/DragonflyDB",
|
|
5
5
|
"homepage": "https://gitlab.polskiepolisy.pl/lib/pp-command-bus",
|
|
6
6
|
"repository": {
|
|
Binary file
|