pp-command-bus 1.0.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 +522 -0
- package/dist/command-bus/command-bus.spec.d.ts +1 -0
- package/dist/command-bus/command-bus.spec.js +398 -0
- package/dist/command-bus/command-bus.spec.js.map +1 -0
- package/dist/command-bus/command.d.ts +24 -0
- package/dist/command-bus/command.js +53 -0
- package/dist/command-bus/command.js.map +1 -0
- package/dist/command-bus/config/command-bus-config.d.ts +40 -0
- package/dist/command-bus/config/command-bus-config.js +59 -0
- package/dist/command-bus/config/command-bus-config.js.map +1 -0
- package/dist/command-bus/config/command-bus-config.spec.d.ts +1 -0
- package/dist/command-bus/config/command-bus-config.spec.js +162 -0
- package/dist/command-bus/config/command-bus-config.spec.js.map +1 -0
- package/dist/command-bus/config/index.d.ts +1 -0
- package/dist/command-bus/config/index.js +9 -0
- package/dist/command-bus/config/index.js.map +1 -0
- package/dist/command-bus/index.d.ts +79 -0
- package/dist/command-bus/index.js +169 -0
- package/dist/command-bus/index.js.map +1 -0
- package/dist/command-bus/job/index.d.ts +6 -0
- package/dist/command-bus/job/index.js +15 -0
- package/dist/command-bus/job/index.js.map +1 -0
- package/dist/command-bus/job/job-options-builder.d.ts +24 -0
- package/dist/command-bus/job/job-options-builder.js +68 -0
- package/dist/command-bus/job/job-options-builder.js.map +1 -0
- package/dist/command-bus/job/job-options-builder.spec.d.ts +1 -0
- package/dist/command-bus/job/job-options-builder.spec.js +163 -0
- package/dist/command-bus/job/job-options-builder.spec.js.map +1 -0
- package/dist/command-bus/job/job-processor.d.ts +33 -0
- package/dist/command-bus/job/job-processor.js +195 -0
- package/dist/command-bus/job/job-processor.js.map +1 -0
- package/dist/command-bus/job/job-processor.spec.d.ts +1 -0
- package/dist/command-bus/job/job-processor.spec.js +352 -0
- package/dist/command-bus/job/job-processor.spec.js.map +1 -0
- package/dist/command-bus/logging/command-logger.d.ts +21 -0
- package/dist/command-bus/logging/command-logger.js +79 -0
- package/dist/command-bus/logging/command-logger.js.map +1 -0
- package/dist/command-bus/logging/command-logger.spec.d.ts +1 -0
- package/dist/command-bus/logging/command-logger.spec.js +245 -0
- package/dist/command-bus/logging/command-logger.spec.js.map +1 -0
- package/dist/command-bus/logging/index.d.ts +5 -0
- package/dist/command-bus/logging/index.js +13 -0
- package/dist/command-bus/logging/index.js.map +1 -0
- package/dist/command-bus/queue/index.d.ts +5 -0
- package/dist/command-bus/queue/index.js +13 -0
- package/dist/command-bus/queue/index.js.map +1 -0
- package/dist/command-bus/queue/queue-manager.d.ts +24 -0
- package/dist/command-bus/queue/queue-manager.js +60 -0
- package/dist/command-bus/queue/queue-manager.js.map +1 -0
- package/dist/command-bus/queue/queue-manager.spec.d.ts +1 -0
- package/dist/command-bus/queue/queue-manager.spec.js +219 -0
- package/dist/command-bus/queue/queue-manager.spec.js.map +1 -0
- package/dist/command-bus/rpc/index.d.ts +5 -0
- package/dist/command-bus/rpc/index.js +13 -0
- package/dist/command-bus/rpc/index.js.map +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.d.ts +45 -0
- package/dist/command-bus/rpc/rpc-coordinator.js +189 -0
- package/dist/command-bus/rpc/rpc-coordinator.js.map +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.d.ts +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.js +286 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.js.map +1 -0
- package/dist/command-bus/types/index.d.ts +57 -0
- package/dist/command-bus/types/index.js +3 -0
- package/dist/command-bus/types/index.js.map +1 -0
- package/dist/command-bus/worker/index.d.ts +5 -0
- package/dist/command-bus/worker/index.js +13 -0
- package/dist/command-bus/worker/index.js.map +1 -0
- package/dist/command-bus/worker/worker-orchestrator.d.ts +46 -0
- package/dist/command-bus/worker/worker-orchestrator.js +160 -0
- package/dist/command-bus/worker/worker-orchestrator.js.map +1 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.d.ts +1 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.js +293 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.js.map +1 -0
- package/dist/examples/rpc.demo.d.ts +2 -0
- package/dist/examples/rpc.demo.js +235 -0
- package/dist/examples/rpc.demo.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/pp-command-bus-1.0.0.tgz +0 -0
- package/dist/shared/config/base-config.d.ts +43 -0
- package/dist/shared/config/base-config.js +100 -0
- package/dist/shared/config/base-config.js.map +1 -0
- package/dist/shared/config/base-config.spec.d.ts +1 -0
- package/dist/shared/config/base-config.spec.js +118 -0
- package/dist/shared/config/base-config.spec.js.map +1 -0
- package/dist/shared/config/index.d.ts +1 -0
- package/dist/shared/config/index.js +9 -0
- package/dist/shared/config/index.js.map +1 -0
- package/dist/shared/logging/index.d.ts +2 -0
- package/dist/shared/logging/index.js +8 -0
- package/dist/shared/logging/index.js.map +1 -0
- package/dist/shared/logging/log-level.d.ts +36 -0
- package/dist/shared/logging/log-level.js +53 -0
- package/dist/shared/logging/log-level.js.map +1 -0
- package/dist/shared/logging/logger.d.ts +42 -0
- package/dist/shared/logging/logger.js +63 -0
- package/dist/shared/logging/logger.js.map +1 -0
- package/dist/shared/logging/logger.spec.d.ts +1 -0
- package/dist/shared/logging/logger.spec.js +89 -0
- package/dist/shared/logging/logger.spec.js.map +1 -0
- package/dist/shared/types.d.ts +26 -0
- package/dist/shared/types.js +6 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RpcCoordinator = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Moduł RPC (Request-Response Pattern)
|
|
9
|
+
* Eksportuje RpcCoordinator do zarządzania wywołaniami RPC
|
|
10
|
+
*/
|
|
11
|
+
var rpc_coordinator_1 = require("./rpc-coordinator");
|
|
12
|
+
Object.defineProperty(exports, "RpcCoordinator", { enumerable: true, get: function () { return __importDefault(rpc_coordinator_1).default; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/command-bus/rpc/index.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,qDAA8D;AAArD,kIAAA,OAAO,OAAkB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { ILogger } from '../../shared/types';
|
|
3
|
+
import type { RpcMetadata } from '../types';
|
|
4
|
+
import type Command from '../command';
|
|
5
|
+
import type { QueueManager } from 'command-bus/queue';
|
|
6
|
+
/**
|
|
7
|
+
* Zarządza lifecycle wywołań RPC bez mapy pending calls
|
|
8
|
+
* Każde wywołanie call() tworzy unikalną kolejkę odpowiedzi
|
|
9
|
+
* Kolejka jest automatycznie kasowana po otrzymaniu odpowiedzi lub timeout
|
|
10
|
+
*/
|
|
11
|
+
export default class RpcCoordinator {
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly redisConnection;
|
|
14
|
+
private readonly queueManager;
|
|
15
|
+
constructor(logger: ILogger, redisConnection: Redis, queueManager: QueueManager);
|
|
16
|
+
/**
|
|
17
|
+
* Przygotowuje komendę RPC z odpowiednimi metadanymi
|
|
18
|
+
* @param command - Komenda do wysłania
|
|
19
|
+
* @param replyQueueName - Nazwa kolejki odpowiedzi
|
|
20
|
+
* @returns Komenda z metadanymi RPC
|
|
21
|
+
*/
|
|
22
|
+
prepareRpcCommand<T extends Command>(command: T, replyQueueName: string): T & {
|
|
23
|
+
__rpcMetadata: RpcMetadata;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Rejestruje nowe wywołanie RPC z timeout
|
|
27
|
+
* Tworzy unikalną kolejkę i worker dla tego wywołania
|
|
28
|
+
* Automatycznie czyści zasoby po zakończeniu (sukces/błąd/timeout)
|
|
29
|
+
*
|
|
30
|
+
* @param correlationId - Unikalny ID wywołania
|
|
31
|
+
* @param commandName - Nazwa komendy
|
|
32
|
+
* @param timeout - Timeout w milisekundach
|
|
33
|
+
* @returns Promise który resolve/reject gdy nadejdzie odpowiedź
|
|
34
|
+
*/
|
|
35
|
+
registerCall<T>(correlationId: string, commandName: string, timeout: number): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Czyści zasoby RPC - zamyka worker i usuwa kolejkę
|
|
38
|
+
* Fail-safe - nie rzuca błędów, tylko loguje
|
|
39
|
+
*
|
|
40
|
+
* @param worker - Worker do zamknięcia
|
|
41
|
+
* @param queue - Kolejka do usunięcia
|
|
42
|
+
* @param queueName - Nazwa kolejki (dla logowania)
|
|
43
|
+
*/
|
|
44
|
+
private cleanupRpcResources;
|
|
45
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const bullmq_1 = require("bullmq");
|
|
13
|
+
/**
|
|
14
|
+
* Zarządza lifecycle wywołań RPC bez mapy pending calls
|
|
15
|
+
* Każde wywołanie call() tworzy unikalną kolejkę odpowiedzi
|
|
16
|
+
* Kolejka jest automatycznie kasowana po otrzymaniu odpowiedzi lub timeout
|
|
17
|
+
*/
|
|
18
|
+
class RpcCoordinator {
|
|
19
|
+
constructor(logger, redisConnection, queueManager) {
|
|
20
|
+
this.logger = logger;
|
|
21
|
+
this.redisConnection = redisConnection;
|
|
22
|
+
this.queueManager = queueManager;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Przygotowuje komendę RPC z odpowiednimi metadanymi
|
|
26
|
+
* @param command - Komenda do wysłania
|
|
27
|
+
* @param replyQueueName - Nazwa kolejki odpowiedzi
|
|
28
|
+
* @returns Komenda z metadanymi RPC
|
|
29
|
+
*/
|
|
30
|
+
prepareRpcCommand(command, replyQueueName) {
|
|
31
|
+
return Object.assign(Object.assign({}, command), { __rpcMetadata: {
|
|
32
|
+
correlationId: command.__id,
|
|
33
|
+
replyQueue: replyQueueName,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Rejestruje nowe wywołanie RPC z timeout
|
|
39
|
+
* Tworzy unikalną kolejkę i worker dla tego wywołania
|
|
40
|
+
* Automatycznie czyści zasoby po zakończeniu (sukces/błąd/timeout)
|
|
41
|
+
*
|
|
42
|
+
* @param correlationId - Unikalny ID wywołania
|
|
43
|
+
* @param commandName - Nazwa komendy
|
|
44
|
+
* @param timeout - Timeout w milisekundach
|
|
45
|
+
* @returns Promise który resolve/reject gdy nadejdzie odpowiedź
|
|
46
|
+
*/
|
|
47
|
+
registerCall(correlationId, commandName, timeout) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const replyQueueName = `rpc-reply-${correlationId}`;
|
|
50
|
+
this.logger.debug('Tworzenie unikalnej kolejki RPC', {
|
|
51
|
+
correlationId,
|
|
52
|
+
replyQueueName,
|
|
53
|
+
commandName,
|
|
54
|
+
timeout: `${timeout}ms`,
|
|
55
|
+
timestamp: new Date().toISOString(),
|
|
56
|
+
});
|
|
57
|
+
// Utwórz dedykowaną kolejkę dla tego wywołania
|
|
58
|
+
const replyQueue = this.queueManager.createQueue(replyQueueName, this.redisConnection);
|
|
59
|
+
// Utwórz dedykowany worker dla tej kolejki (concurrency=1, jedna odpowiedź)
|
|
60
|
+
let replyWorker;
|
|
61
|
+
let timeoutId;
|
|
62
|
+
try {
|
|
63
|
+
// Promise dla odpowiedzi z workera
|
|
64
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
65
|
+
replyWorker = new bullmq_1.Worker(`{${replyQueueName}}`, (job) => {
|
|
66
|
+
const { correlationId: jobCorrelationId, result, error } = job.data;
|
|
67
|
+
this.logger.debug('Otrzymano odpowiedź RPC', {
|
|
68
|
+
correlationId: jobCorrelationId,
|
|
69
|
+
hasResult: result !== undefined,
|
|
70
|
+
hasError: error !== undefined,
|
|
71
|
+
timestamp: new Date().toISOString(),
|
|
72
|
+
});
|
|
73
|
+
if (error) {
|
|
74
|
+
this.logger.error('Wywołanie RPC odrzucone', {
|
|
75
|
+
correlationId: jobCorrelationId,
|
|
76
|
+
error,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
});
|
|
79
|
+
reject(new Error(error));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.logger.debug('Wywołanie RPC rozwiązane', {
|
|
83
|
+
correlationId: jobCorrelationId,
|
|
84
|
+
timestamp: new Date().toISOString(),
|
|
85
|
+
});
|
|
86
|
+
resolve(result);
|
|
87
|
+
}
|
|
88
|
+
return Promise.resolve();
|
|
89
|
+
}, {
|
|
90
|
+
connection: this.redisConnection,
|
|
91
|
+
concurrency: 1, // Tylko jedna odpowiedź per wywołanie
|
|
92
|
+
});
|
|
93
|
+
this.logger.debug('Worker RPC utworzony', {
|
|
94
|
+
correlationId,
|
|
95
|
+
replyQueueName,
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
// Promise dla timeout
|
|
100
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
101
|
+
timeoutId = setTimeout(() => {
|
|
102
|
+
this.logger.error('RPC timeout', {
|
|
103
|
+
commandName,
|
|
104
|
+
commandId: correlationId,
|
|
105
|
+
timeout: `${timeout}ms`,
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
});
|
|
108
|
+
reject(new Error(`RPC timeout for command ${commandName}`));
|
|
109
|
+
}, timeout);
|
|
110
|
+
});
|
|
111
|
+
// Czekaj na odpowiedź lub timeout (co nastąpi pierwsze)
|
|
112
|
+
return yield Promise.race([responsePromise, timeoutPromise]);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
// Wyczyść timeout jeśli istnieje
|
|
116
|
+
if (timeoutId) {
|
|
117
|
+
clearTimeout(timeoutId);
|
|
118
|
+
}
|
|
119
|
+
// Cleanup zasobów (zawsze, niezależnie od wyniku)
|
|
120
|
+
yield this.cleanupRpcResources(replyWorker, replyQueue, replyQueueName);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Czyści zasoby RPC - zamyka worker i usuwa kolejkę
|
|
126
|
+
* Fail-safe - nie rzuca błędów, tylko loguje
|
|
127
|
+
*
|
|
128
|
+
* @param worker - Worker do zamknięcia
|
|
129
|
+
* @param queue - Kolejka do usunięcia
|
|
130
|
+
* @param queueName - Nazwa kolejki (dla logowania)
|
|
131
|
+
*/
|
|
132
|
+
cleanupRpcResources(worker, queue, queueName) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
this.logger.debug('Rozpoczynam cleanup zasobów RPC', {
|
|
135
|
+
queueName,
|
|
136
|
+
timestamp: new Date().toISOString(),
|
|
137
|
+
});
|
|
138
|
+
// Zamknij worker
|
|
139
|
+
if (worker) {
|
|
140
|
+
try {
|
|
141
|
+
yield worker.close();
|
|
142
|
+
this.logger.debug('Worker RPC zamknięty', {
|
|
143
|
+
queueName,
|
|
144
|
+
timestamp: new Date().toISOString(),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
this.logger.warn('Błąd podczas zamykania Worker RPC', {
|
|
149
|
+
queueName,
|
|
150
|
+
error: error instanceof Error ? error.message : String(error),
|
|
151
|
+
timestamp: new Date().toISOString(),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Usuń kolejkę całkowicie (obliterate + close)
|
|
156
|
+
try {
|
|
157
|
+
yield queue.obliterate({ force: true });
|
|
158
|
+
this.logger.debug('Kolejka RPC usunięta (obliterate)', {
|
|
159
|
+
queueName,
|
|
160
|
+
timestamp: new Date().toISOString(),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.logger.warn('Błąd podczas obliterate kolejki RPC', {
|
|
165
|
+
queueName,
|
|
166
|
+
error: error instanceof Error ? error.message : String(error),
|
|
167
|
+
timestamp: new Date().toISOString(),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Zamknij kolejkę
|
|
171
|
+
try {
|
|
172
|
+
yield queue.close();
|
|
173
|
+
this.logger.debug('Kolejka RPC zamknięta', {
|
|
174
|
+
queueName,
|
|
175
|
+
timestamp: new Date().toISOString(),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
this.logger.warn('Błąd podczas zamykania kolejki RPC', {
|
|
180
|
+
queueName,
|
|
181
|
+
error: error instanceof Error ? error.message : String(error),
|
|
182
|
+
timestamp: new Date().toISOString(),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.default = RpcCoordinator;
|
|
189
|
+
//# sourceMappingURL=rpc-coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-coordinator.js","sourceRoot":"","s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,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBAC7D,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACpC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KAAA;CACF;AAnMD,iCAmMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const bullmq_1 = require("bullmq");
|
|
16
|
+
const rpc_coordinator_1 = __importDefault(require("./rpc-coordinator"));
|
|
17
|
+
const command_1 = __importDefault(require("../command"));
|
|
18
|
+
// Mock BullMQ
|
|
19
|
+
jest.mock('bullmq');
|
|
20
|
+
describe('RpcCoordinator - Uproszczona architektura z unikalnymi kolejkami', () => {
|
|
21
|
+
let rpcCoordinator;
|
|
22
|
+
let mockLogger;
|
|
23
|
+
let mockQueue;
|
|
24
|
+
let mockWorker;
|
|
25
|
+
let mockRedisConnection;
|
|
26
|
+
let mockQueueManager;
|
|
27
|
+
// Mock Command class for testing
|
|
28
|
+
class TestCommand extends command_1.default {
|
|
29
|
+
constructor(value) {
|
|
30
|
+
super();
|
|
31
|
+
this.value = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
mockLogger = {
|
|
37
|
+
log: jest.fn(),
|
|
38
|
+
error: jest.fn(),
|
|
39
|
+
warn: jest.fn(),
|
|
40
|
+
debug: jest.fn(),
|
|
41
|
+
};
|
|
42
|
+
// Mock Redis connection
|
|
43
|
+
mockRedisConnection = {};
|
|
44
|
+
// Mock Queue
|
|
45
|
+
mockQueue = {
|
|
46
|
+
add: jest.fn().mockResolvedValue({ id: 'test-job-id' }),
|
|
47
|
+
close: jest.fn().mockResolvedValue(undefined),
|
|
48
|
+
obliterate: jest.fn().mockResolvedValue(undefined),
|
|
49
|
+
};
|
|
50
|
+
// Mock Worker
|
|
51
|
+
mockWorker = {
|
|
52
|
+
close: jest.fn().mockResolvedValue(undefined),
|
|
53
|
+
on: jest.fn().mockReturnThis(),
|
|
54
|
+
};
|
|
55
|
+
// Mock QueueManager
|
|
56
|
+
mockQueueManager = {
|
|
57
|
+
createQueue: jest.fn().mockReturnValue(mockQueue),
|
|
58
|
+
};
|
|
59
|
+
// Mock konstruktorów
|
|
60
|
+
bullmq_1.Queue.mockImplementation(() => mockQueue);
|
|
61
|
+
bullmq_1.Worker.mockImplementation(() => mockWorker);
|
|
62
|
+
rpcCoordinator = new rpc_coordinator_1.default(mockLogger, mockRedisConnection, mockQueueManager);
|
|
63
|
+
});
|
|
64
|
+
describe('registerCall - tworzy unikalną kolejkę dla każdego wywołania', () => {
|
|
65
|
+
it('powinno utworzyć kolejkę z nazwą rpc-reply-{correlationId}', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
// Given
|
|
67
|
+
const correlationId = 'test-correlation-123';
|
|
68
|
+
const commandName = 'TestCommand';
|
|
69
|
+
const timeout = 5000;
|
|
70
|
+
// Symuluj Worker handler który natychmiast resolve'uje
|
|
71
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
72
|
+
const simulateReply = (result) => {
|
|
73
|
+
if (workerCalls.length > 0) {
|
|
74
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
75
|
+
const job = {
|
|
76
|
+
data: {
|
|
77
|
+
correlationId,
|
|
78
|
+
result,
|
|
79
|
+
error: null,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return handler(job);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// When
|
|
86
|
+
const promise = rpcCoordinator.registerCall(correlationId, commandName, timeout);
|
|
87
|
+
// Symuluj odpowiedź
|
|
88
|
+
yield simulateReply({ success: true });
|
|
89
|
+
// Then
|
|
90
|
+
yield expect(promise).resolves.toEqual({ success: true });
|
|
91
|
+
expect(mockQueueManager.createQueue).toHaveBeenCalledWith(`rpc-reply-${correlationId}`, mockRedisConnection);
|
|
92
|
+
}));
|
|
93
|
+
it('powinno utworzyć Worker dla kolejki odpowiedzi', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
// Given
|
|
95
|
+
const correlationId = 'test-correlation-456';
|
|
96
|
+
const commandName = 'TestCommand';
|
|
97
|
+
const timeout = 5000;
|
|
98
|
+
// When
|
|
99
|
+
const promise = rpcCoordinator.registerCall(correlationId, commandName, timeout);
|
|
100
|
+
// Symuluj odpowiedź
|
|
101
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
102
|
+
if (workerCalls.length > 0) {
|
|
103
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
104
|
+
yield handler({
|
|
105
|
+
data: { correlationId, result: 'ok', error: null },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Then
|
|
109
|
+
yield promise;
|
|
110
|
+
expect(bullmq_1.Worker).toHaveBeenCalledWith(`{rpc-reply-${correlationId}}`, expect.any(Function), expect.objectContaining({
|
|
111
|
+
connection: mockRedisConnection,
|
|
112
|
+
concurrency: 1,
|
|
113
|
+
}));
|
|
114
|
+
}));
|
|
115
|
+
it('powinno zwrócić wynik po otrzymaniu odpowiedzi', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
// Given
|
|
117
|
+
const correlationId = 'test-correlation-789';
|
|
118
|
+
const result = { data: 42, status: 'success' };
|
|
119
|
+
// When
|
|
120
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', 5000);
|
|
121
|
+
// Symuluj odpowiedź
|
|
122
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
123
|
+
if (workerCalls.length > 0) {
|
|
124
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
125
|
+
yield handler({
|
|
126
|
+
data: { correlationId, result, error: null },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Then
|
|
130
|
+
yield expect(promise).resolves.toEqual(result);
|
|
131
|
+
}));
|
|
132
|
+
it('powinno rzucić błąd po otrzymaniu error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
// Given
|
|
134
|
+
const correlationId = 'test-correlation-error';
|
|
135
|
+
const errorMessage = 'Test error message';
|
|
136
|
+
// When
|
|
137
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', 5000);
|
|
138
|
+
// Symuluj błąd
|
|
139
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
140
|
+
if (workerCalls.length > 0) {
|
|
141
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
142
|
+
yield handler({
|
|
143
|
+
data: { correlationId, result: null, error: errorMessage },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// Then
|
|
147
|
+
yield expect(promise).rejects.toThrow(errorMessage);
|
|
148
|
+
}));
|
|
149
|
+
it('powinno rzucić błąd timeout gdy brak odpowiedzi', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
// Given
|
|
151
|
+
const correlationId = 'test-correlation-timeout';
|
|
152
|
+
const timeout = 100; // 100ms timeout
|
|
153
|
+
// When
|
|
154
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', timeout);
|
|
155
|
+
// Then - czekaj na timeout
|
|
156
|
+
yield expect(promise).rejects.toThrow('RPC timeout for command TestCommand');
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
describe('cleanup kolejki po zakończeniu', () => {
|
|
160
|
+
it('powinno usunąć kolejkę po otrzymaniu odpowiedzi (sukces)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
// Given
|
|
162
|
+
const correlationId = 'test-cleanup-success';
|
|
163
|
+
// When
|
|
164
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', 5000);
|
|
165
|
+
// Symuluj odpowiedź
|
|
166
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
167
|
+
if (workerCalls.length > 0) {
|
|
168
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
169
|
+
yield handler({
|
|
170
|
+
data: { correlationId, result: 'ok', error: null },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// Czekaj na zakończenie promise (cleanup jest w finally)
|
|
174
|
+
yield promise;
|
|
175
|
+
// Daj czas na asynchroniczny cleanup
|
|
176
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
177
|
+
// Then
|
|
178
|
+
expect(mockWorker.close).toHaveBeenCalled();
|
|
179
|
+
expect(mockQueue.obliterate).toHaveBeenCalledWith({ force: true });
|
|
180
|
+
expect(mockQueue.close).toHaveBeenCalled();
|
|
181
|
+
}));
|
|
182
|
+
it('powinno usunąć kolejkę po otrzymaniu błędu', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
// Given
|
|
184
|
+
const correlationId = 'test-cleanup-error';
|
|
185
|
+
// When
|
|
186
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', 5000);
|
|
187
|
+
// Symuluj błąd
|
|
188
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
189
|
+
if (workerCalls.length > 0) {
|
|
190
|
+
const handler = workerCalls[workerCalls.length - 1][1];
|
|
191
|
+
yield handler({
|
|
192
|
+
data: { correlationId, result: null, error: 'error' },
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// Czekaj na odrzucenie promise
|
|
196
|
+
yield expect(promise).rejects.toThrow();
|
|
197
|
+
// Daj czas na asynchroniczny cleanup
|
|
198
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
199
|
+
// Then
|
|
200
|
+
expect(mockWorker.close).toHaveBeenCalled();
|
|
201
|
+
expect(mockQueue.obliterate).toHaveBeenCalledWith({ force: true });
|
|
202
|
+
expect(mockQueue.close).toHaveBeenCalled();
|
|
203
|
+
}));
|
|
204
|
+
it('powinno usunąć kolejkę po timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
|
+
// Given
|
|
206
|
+
const correlationId = 'test-cleanup-timeout';
|
|
207
|
+
const timeout = 100;
|
|
208
|
+
// When
|
|
209
|
+
const promise = rpcCoordinator.registerCall(correlationId, 'TestCommand', timeout);
|
|
210
|
+
// Czekaj na timeout
|
|
211
|
+
yield expect(promise).rejects.toThrow();
|
|
212
|
+
// Daj czas na asynchroniczny cleanup (cleanup jest w finally)
|
|
213
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
214
|
+
// Then - cleanup powinien zostać wywołany
|
|
215
|
+
expect(mockWorker.close).toHaveBeenCalled();
|
|
216
|
+
expect(mockQueue.obliterate).toHaveBeenCalledWith({ force: true });
|
|
217
|
+
expect(mockQueue.close).toHaveBeenCalled();
|
|
218
|
+
}));
|
|
219
|
+
});
|
|
220
|
+
describe('równoległe wywołania RPC', () => {
|
|
221
|
+
it('każde wywołanie powinno mieć własną kolejkę', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
// Given
|
|
223
|
+
const call1 = 'correlation-1';
|
|
224
|
+
const call2 = 'correlation-2';
|
|
225
|
+
// When
|
|
226
|
+
const promise1 = rpcCoordinator.registerCall(call1, 'Command1', 5000);
|
|
227
|
+
const promise2 = rpcCoordinator.registerCall(call2, 'Command2', 5000);
|
|
228
|
+
// Then - sprawdź że utworzono dwie kolejki
|
|
229
|
+
expect(mockQueueManager.createQueue).toHaveBeenCalledWith(`rpc-reply-${call1}`, mockRedisConnection);
|
|
230
|
+
expect(mockQueueManager.createQueue).toHaveBeenCalledWith(`rpc-reply-${call2}`, mockRedisConnection);
|
|
231
|
+
// Symuluj odpowiedzi dla odpowiednich workerów
|
|
232
|
+
const workerCalls = bullmq_1.Worker.mock.calls;
|
|
233
|
+
// Pierwszy worker - odpowiedź dla call1
|
|
234
|
+
const handler1 = workerCalls[0][1];
|
|
235
|
+
yield handler1({
|
|
236
|
+
data: {
|
|
237
|
+
correlationId: call1,
|
|
238
|
+
result: 'ok',
|
|
239
|
+
error: null,
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
// Drugi worker - odpowiedź dla call2
|
|
243
|
+
const handler2 = workerCalls[1][1];
|
|
244
|
+
yield handler2({
|
|
245
|
+
data: {
|
|
246
|
+
correlationId: call2,
|
|
247
|
+
result: 'ok',
|
|
248
|
+
error: null,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
// Czekaj na zakończenie obu wywołań
|
|
252
|
+
yield Promise.all([promise1, promise2]);
|
|
253
|
+
// Daj czas na asynchroniczny cleanup
|
|
254
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
255
|
+
}));
|
|
256
|
+
});
|
|
257
|
+
describe('prepareRpcCommand', () => {
|
|
258
|
+
it('powinno dodać __rpcMetadata do komendy', () => {
|
|
259
|
+
// Given
|
|
260
|
+
const command = new TestCommand(42);
|
|
261
|
+
const replyQueueName = 'rpc-reply-test-123';
|
|
262
|
+
// When
|
|
263
|
+
const result = rpcCoordinator.prepareRpcCommand(command, replyQueueName);
|
|
264
|
+
// Then
|
|
265
|
+
expect(result).toHaveProperty('__rpcMetadata');
|
|
266
|
+
expect(result.__rpcMetadata).toEqual(expect.objectContaining({
|
|
267
|
+
correlationId: command.__id,
|
|
268
|
+
replyQueue: replyQueueName,
|
|
269
|
+
timestamp: expect.any(Number),
|
|
270
|
+
}));
|
|
271
|
+
});
|
|
272
|
+
it('powinno zachować wszystkie właściwości komendy', () => {
|
|
273
|
+
// Given
|
|
274
|
+
const command = new TestCommand(42);
|
|
275
|
+
const replyQueueName = 'rpc-reply-test-456';
|
|
276
|
+
// When
|
|
277
|
+
const result = rpcCoordinator.prepareRpcCommand(command, replyQueueName);
|
|
278
|
+
// Then
|
|
279
|
+
expect(result.value).toBe(42);
|
|
280
|
+
expect(result.__name).toBe(command.__name);
|
|
281
|
+
expect(result.__id).toBe(command.__id);
|
|
282
|
+
expect(result.__time).toBe(command.__time);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
//# sourceMappingURL=rpc-coordinator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-coordinator.spec.js","sourceRoot":"","sources":["../../../src/command-bus/rpc/rpc-coordinator.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mCAAuC;AAGvC,wEAA+C;AAC/C,yDAAiC;AAIjC,cAAc;AACd,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAEpB,QAAQ,CAAC,kEAAkE,EAAE,GAAG,EAAE;IAChF,IAAI,cAA8B,CAAC;IACnC,IAAI,UAAmB,CAAC;IACxB,IAAI,SAA6B,CAAC;IAClC,IAAI,UAA+B,CAAC;IACpC,IAAI,mBAAuC,CAAC;IAC5C,IAAI,gBAA2C,CAAC;IAEhD,iCAAiC;IACjC,MAAM,WAAY,SAAQ,iBAAO;QAC/B,YAAmB,KAAa;YAC9B,KAAK,EAAE,CAAC;YADS,UAAK,GAAL,KAAK,CAAQ;QAEhC,CAAC;KACF;IAED,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,UAAU,GA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gBAC3B,UAAU,EAAE,cAAc;gBAC1B,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAC9B,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,QAAQ;YACR,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;YACpC,MAAM,cAAc,GAAG,oBAAoB,CAAC;YAE5C,OAAO;YACP,MAAM,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YAEzE,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Job } from 'bullmq';
|
|
2
|
+
import type { TCallableAsync } from '../../shared/types';
|
|
3
|
+
/**
|
|
4
|
+
* Metadane dla wywołania RPC
|
|
5
|
+
*/
|
|
6
|
+
export interface RpcMetadata {
|
|
7
|
+
correlationId: string;
|
|
8
|
+
replyQueue: string;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler dla komendy
|
|
13
|
+
*/
|
|
14
|
+
export type CommandHandler = TCallableAsync;
|
|
15
|
+
/**
|
|
16
|
+
* Opcje dla jobów BullMQ
|
|
17
|
+
*/
|
|
18
|
+
export interface JobOptions {
|
|
19
|
+
removeOnComplete: boolean | {
|
|
20
|
+
age?: number;
|
|
21
|
+
count?: number;
|
|
22
|
+
};
|
|
23
|
+
removeOnFail: {
|
|
24
|
+
count: number;
|
|
25
|
+
age: number;
|
|
26
|
+
};
|
|
27
|
+
attempts: number;
|
|
28
|
+
backoff: {
|
|
29
|
+
type: 'exponential';
|
|
30
|
+
delay: number;
|
|
31
|
+
};
|
|
32
|
+
lifo: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Worker processor function
|
|
36
|
+
*/
|
|
37
|
+
export type WorkerProcessor = (job: Job) => Promise<unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Statystyki pamięci dla CommandBus
|
|
40
|
+
*
|
|
41
|
+
* Uwaga: RpcCoordinator nie ma już centralnej mapy pending calls.
|
|
42
|
+
* Każde wywołanie RPC tworzy dedykowaną kolejkę i worker,
|
|
43
|
+
* które są automatycznie kasowane po zakończeniu.
|
|
44
|
+
*/
|
|
45
|
+
export interface MemoryStats {
|
|
46
|
+
queues: {
|
|
47
|
+
commandQueuesCount: number;
|
|
48
|
+
};
|
|
49
|
+
workers: {
|
|
50
|
+
activeWorkersCount: number;
|
|
51
|
+
workerNames: string[];
|
|
52
|
+
};
|
|
53
|
+
handlers: {
|
|
54
|
+
registeredHandlersCount: number;
|
|
55
|
+
handlerNames: string[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/command-bus/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WorkerOrchestrator = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Moduł zarządzania workerami BullMQ
|
|
9
|
+
* Eksportuje WorkerOrchestrator odpowiedzialny za lifecycle workerów
|
|
10
|
+
*/
|
|
11
|
+
var worker_orchestrator_1 = require("./worker-orchestrator");
|
|
12
|
+
Object.defineProperty(exports, "WorkerOrchestrator", { enumerable: true, get: function () { return __importDefault(worker_orchestrator_1).default; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/command-bus/worker/index.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,6DAAsE;AAA7D,0IAAA,OAAO,OAAsB"}
|