pp-command-bus 1.5.0 → 2.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 +400 -1219
- package/dist/command-bus/command-bus.spec.js +138 -359
- package/dist/command-bus/command-bus.spec.js.map +1 -1
- package/dist/command-bus/command.d.ts +3 -4
- package/dist/command-bus/command.js +3 -32
- package/dist/command-bus/command.js.map +1 -1
- package/dist/command-bus/config/command-bus-config.d.ts +75 -21
- package/dist/command-bus/config/command-bus-config.js +99 -58
- package/dist/command-bus/config/command-bus-config.js.map +1 -1
- package/dist/command-bus/config/command-bus-config.spec.js +174 -100
- package/dist/command-bus/config/command-bus-config.spec.js.map +1 -1
- package/dist/command-bus/index.d.ts +39 -52
- package/dist/command-bus/index.js +133 -126
- package/dist/command-bus/index.js.map +1 -1
- package/dist/command-bus/logging/command-logger.d.ts +2 -0
- package/dist/command-bus/logging/command-logger.js +7 -0
- package/dist/command-bus/logging/command-logger.js.map +1 -1
- package/dist/command-bus/logging/command-logger.spec.js +36 -0
- package/dist/command-bus/logging/command-logger.spec.js.map +1 -1
- package/dist/command-bus/serialization/index.d.ts +6 -0
- package/dist/command-bus/serialization/index.js +9 -0
- package/dist/command-bus/serialization/index.js.map +1 -0
- package/dist/command-bus/serialization/msgpack-serializer.d.ts +26 -0
- package/dist/command-bus/serialization/msgpack-serializer.js +70 -0
- package/dist/command-bus/serialization/msgpack-serializer.js.map +1 -0
- package/dist/command-bus/serialization/msgpack-serializer.spec.js +223 -0
- package/dist/command-bus/serialization/msgpack-serializer.spec.js.map +1 -0
- package/dist/command-bus/serialization/serializer.interface.d.ts +21 -0
- package/dist/command-bus/serialization/serializer.interface.js +3 -0
- package/dist/command-bus/serialization/serializer.interface.js.map +1 -0
- package/dist/command-bus/transport/consumer-loop.d.ts +45 -0
- package/dist/command-bus/transport/consumer-loop.js +90 -0
- package/dist/command-bus/transport/consumer-loop.js.map +1 -0
- package/dist/command-bus/transport/consumer-loop.spec.js +216 -0
- package/dist/command-bus/transport/consumer-loop.spec.js.map +1 -0
- package/dist/command-bus/transport/index.d.ts +21 -0
- package/dist/command-bus/transport/index.js +23 -0
- package/dist/command-bus/transport/index.js.map +1 -0
- package/dist/command-bus/transport/message-processor.d.ts +59 -0
- package/dist/command-bus/transport/message-processor.js +111 -0
- package/dist/command-bus/transport/message-processor.js.map +1 -0
- package/dist/command-bus/transport/message-processor.spec.js +185 -0
- package/dist/command-bus/transport/message-processor.spec.js.map +1 -0
- package/dist/command-bus/transport/pending-recovery.d.ts +54 -0
- package/dist/command-bus/transport/pending-recovery.js +139 -0
- package/dist/command-bus/transport/pending-recovery.js.map +1 -0
- package/dist/command-bus/transport/pending-recovery.spec.js +176 -0
- package/dist/command-bus/transport/pending-recovery.spec.js.map +1 -0
- package/dist/command-bus/transport/redis-codec.d.ts +24 -0
- package/dist/command-bus/transport/redis-codec.js +33 -0
- package/dist/command-bus/transport/redis-codec.js.map +1 -0
- package/dist/command-bus/transport/redis-codec.spec.js +53 -0
- package/dist/command-bus/transport/redis-codec.spec.js.map +1 -0
- package/dist/command-bus/transport/redis-streams-transport.d.ts +91 -0
- package/dist/command-bus/transport/redis-streams-transport.js +134 -0
- package/dist/command-bus/transport/redis-streams-transport.js.map +1 -0
- package/dist/command-bus/transport/redis-streams-transport.spec.js +420 -0
- package/dist/command-bus/transport/redis-streams-transport.spec.js.map +1 -0
- package/dist/command-bus/transport/rpc-handler.d.ts +39 -0
- package/dist/command-bus/transport/rpc-handler.js +87 -0
- package/dist/command-bus/transport/rpc-handler.js.map +1 -0
- package/dist/command-bus/transport/rpc-handler.spec.js +157 -0
- package/dist/command-bus/transport/rpc-handler.spec.js.map +1 -0
- package/dist/command-bus/transport/stream-consumer.d.ts +89 -0
- package/dist/command-bus/transport/stream-consumer.js +181 -0
- package/dist/command-bus/transport/stream-consumer.js.map +1 -0
- package/dist/command-bus/transport/stream-consumer.spec.js +284 -0
- package/dist/command-bus/transport/stream-consumer.spec.js.map +1 -0
- package/dist/command-bus/transport/stream-producer.d.ts +23 -0
- package/dist/command-bus/transport/stream-producer.js +70 -0
- package/dist/command-bus/transport/stream-producer.js.map +1 -0
- package/dist/command-bus/transport/stream-producer.spec.js +125 -0
- package/dist/command-bus/transport/stream-producer.spec.js.map +1 -0
- package/dist/command-bus/transport/transport.interface.d.ts +87 -0
- package/dist/command-bus/transport/transport.interface.js +3 -0
- package/dist/command-bus/transport/transport.interface.js.map +1 -0
- package/dist/command-bus/types/index.d.ts +0 -84
- package/dist/examples/rpc.demo.js +1 -1
- package/dist/examples/rpc.demo.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/pp-command-bus-2.0.0.tgz +0 -0
- package/dist/shared/redis/connection-pool.d.ts +54 -0
- package/dist/shared/redis/connection-pool.js +117 -0
- package/dist/shared/redis/connection-pool.js.map +1 -0
- package/dist/shared/redis/connection-pool.spec.js +114 -0
- package/dist/shared/redis/connection-pool.spec.js.map +1 -0
- package/dist/shared/redis/index.d.ts +5 -3
- package/dist/shared/redis/index.js +6 -4
- package/dist/shared/redis/index.js.map +1 -1
- package/dist/shared/redis/rpc-connection-pool.d.ts +61 -0
- package/dist/shared/redis/rpc-connection-pool.js +154 -0
- package/dist/shared/redis/rpc-connection-pool.js.map +1 -0
- package/dist/shared/redis/rpc-connection-pool.spec.d.ts +1 -0
- package/dist/shared/redis/rpc-connection-pool.spec.js +173 -0
- package/dist/shared/redis/rpc-connection-pool.spec.js.map +1 -0
- package/dist/shared/types.d.ts +0 -4
- package/dist/shared/utils/error-utils.d.ts +8 -0
- package/dist/shared/utils/error-utils.js +14 -0
- package/dist/shared/utils/error-utils.js.map +1 -0
- package/package.json +12 -12
- package/dist/command-bus/config/auto-config-optimizer.d.ts +0 -35
- package/dist/command-bus/config/auto-config-optimizer.js +0 -52
- package/dist/command-bus/config/auto-config-optimizer.js.map +0 -1
- package/dist/command-bus/config/auto-config-optimizer.spec.js +0 -42
- package/dist/command-bus/config/auto-config-optimizer.spec.js.map +0 -1
- package/dist/command-bus/job/index.d.ts +0 -6
- package/dist/command-bus/job/index.js +0 -15
- package/dist/command-bus/job/index.js.map +0 -1
- package/dist/command-bus/job/job-options-builder.d.ts +0 -21
- package/dist/command-bus/job/job-options-builder.js +0 -58
- package/dist/command-bus/job/job-options-builder.js.map +0 -1
- package/dist/command-bus/job/job-options-builder.spec.js +0 -156
- package/dist/command-bus/job/job-options-builder.spec.js.map +0 -1
- package/dist/command-bus/job/job-processor.d.ts +0 -39
- package/dist/command-bus/job/job-processor.js +0 -203
- package/dist/command-bus/job/job-processor.js.map +0 -1
- package/dist/command-bus/job/job-processor.spec.js +0 -436
- package/dist/command-bus/job/job-processor.spec.js.map +0 -1
- package/dist/command-bus/queue/index.d.ts +0 -5
- package/dist/command-bus/queue/index.js +0 -13
- package/dist/command-bus/queue/index.js.map +0 -1
- package/dist/command-bus/queue/queue-manager.d.ts +0 -56
- package/dist/command-bus/queue/queue-manager.js +0 -163
- package/dist/command-bus/queue/queue-manager.js.map +0 -1
- package/dist/command-bus/queue/queue-manager.spec.js +0 -371
- package/dist/command-bus/queue/queue-manager.spec.js.map +0 -1
- package/dist/command-bus/rpc/index.d.ts +0 -11
- package/dist/command-bus/rpc/index.js +0 -19
- package/dist/command-bus/rpc/index.js.map +0 -1
- package/dist/command-bus/rpc/payload-compression.service.d.ts +0 -50
- package/dist/command-bus/rpc/payload-compression.service.js +0 -215
- package/dist/command-bus/rpc/payload-compression.service.js.map +0 -1
- package/dist/command-bus/rpc/payload-compression.service.spec.js +0 -376
- package/dist/command-bus/rpc/payload-compression.service.spec.js.map +0 -1
- package/dist/command-bus/rpc/rpc-coordinator.d.ts +0 -96
- package/dist/command-bus/rpc/rpc-coordinator.js +0 -500
- package/dist/command-bus/rpc/rpc-coordinator.js.map +0 -1
- package/dist/command-bus/rpc/rpc-coordinator.spec.js +0 -621
- package/dist/command-bus/rpc/rpc-coordinator.spec.js.map +0 -1
- package/dist/command-bus/rpc/rpc-job-cancellation.service.d.ts +0 -82
- package/dist/command-bus/rpc/rpc-job-cancellation.service.js +0 -180
- package/dist/command-bus/rpc/rpc-job-cancellation.service.js.map +0 -1
- package/dist/command-bus/rpc/rpc-job-cancellation.service.spec.js +0 -286
- package/dist/command-bus/rpc/rpc-job-cancellation.service.spec.js.map +0 -1
- package/dist/command-bus/worker/index.d.ts +0 -10
- package/dist/command-bus/worker/index.js +0 -19
- package/dist/command-bus/worker/index.js.map +0 -1
- package/dist/command-bus/worker/worker-benchmark.d.ts +0 -71
- package/dist/command-bus/worker/worker-benchmark.js +0 -202
- package/dist/command-bus/worker/worker-benchmark.js.map +0 -1
- package/dist/command-bus/worker/worker-benchmark.spec.js +0 -310
- package/dist/command-bus/worker/worker-benchmark.spec.js.map +0 -1
- package/dist/command-bus/worker/worker-metrics-collector.d.ts +0 -98
- package/dist/command-bus/worker/worker-metrics-collector.js +0 -242
- package/dist/command-bus/worker/worker-metrics-collector.js.map +0 -1
- package/dist/command-bus/worker/worker-orchestrator.d.ts +0 -70
- package/dist/command-bus/worker/worker-orchestrator.js +0 -339
- package/dist/command-bus/worker/worker-orchestrator.js.map +0 -1
- package/dist/command-bus/worker/worker-orchestrator.spec.js +0 -712
- package/dist/command-bus/worker/worker-orchestrator.spec.js.map +0 -1
- package/dist/examples/auto-config.demo.d.ts +0 -9
- package/dist/examples/auto-config.demo.js +0 -106
- package/dist/examples/auto-config.demo.js.map +0 -1
- package/dist/examples/rpc-compression.demo.d.ts +0 -5
- package/dist/examples/rpc-compression.demo.js +0 -358
- package/dist/examples/rpc-compression.demo.js.map +0 -1
- package/dist/examples/rpc-resilience.demo.d.ts +0 -15
- package/dist/examples/rpc-resilience.demo.js +0 -233
- package/dist/examples/rpc-resilience.demo.js.map +0 -1
- package/dist/pp-command-bus-1.5.0.tgz +0 -0
- package/dist/shared/config/base-config.d.ts +0 -54
- package/dist/shared/config/base-config.js +0 -114
- package/dist/shared/config/base-config.js.map +0 -1
- package/dist/shared/config/base-config.spec.js +0 -204
- package/dist/shared/config/base-config.spec.js.map +0 -1
- package/dist/shared/config/index.d.ts +0 -1
- package/dist/shared/config/index.js +0 -9
- package/dist/shared/config/index.js.map +0 -1
- package/dist/shared/redis/redis-connection-factory.d.ts +0 -66
- package/dist/shared/redis/redis-connection-factory.js +0 -113
- package/dist/shared/redis/redis-connection-factory.js.map +0 -1
- /package/dist/command-bus/{config/auto-config-optimizer.spec.d.ts → serialization/msgpack-serializer.spec.d.ts} +0 -0
- /package/dist/command-bus/{job/job-options-builder.spec.d.ts → transport/consumer-loop.spec.d.ts} +0 -0
- /package/dist/command-bus/{job/job-processor.spec.d.ts → transport/message-processor.spec.d.ts} +0 -0
- /package/dist/command-bus/{queue/queue-manager.spec.d.ts → transport/pending-recovery.spec.d.ts} +0 -0
- /package/dist/command-bus/{rpc/payload-compression.service.spec.d.ts → transport/redis-codec.spec.d.ts} +0 -0
- /package/dist/command-bus/{rpc/rpc-coordinator.spec.d.ts → transport/redis-streams-transport.spec.d.ts} +0 -0
- /package/dist/command-bus/{rpc/rpc-job-cancellation.service.spec.d.ts → transport/rpc-handler.spec.d.ts} +0 -0
- /package/dist/command-bus/{worker/worker-benchmark.spec.d.ts → transport/stream-consumer.spec.d.ts} +0 -0
- /package/dist/command-bus/{worker/worker-orchestrator.spec.d.ts → transport/stream-producer.spec.d.ts} +0 -0
- /package/dist/shared/{config/base-config.spec.d.ts → redis/connection-pool.spec.d.ts} +0 -0
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { ILogger } from '../../shared/types';
|
|
2
|
-
/**
|
|
3
|
-
* Rekomendacja zmiany concurrency
|
|
4
|
-
*/
|
|
5
|
-
interface ConcurrencyRecommendation {
|
|
6
|
-
shouldAdjust: boolean;
|
|
7
|
-
direction: 'increase' | 'decrease' | 'none';
|
|
8
|
-
reason: string;
|
|
9
|
-
currentMetrics: {
|
|
10
|
-
activeCount: number;
|
|
11
|
-
completedCount: number;
|
|
12
|
-
avgProcessingTimeMs: number;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Zbiera metryki workera w trybie event-driven
|
|
17
|
-
* Resetuje dane co 1 minutę (okno profilowania)
|
|
18
|
-
* Nie używa setInterval - bazuje na eventach jobów
|
|
19
|
-
*/
|
|
20
|
-
export default class WorkerMetricsCollector {
|
|
21
|
-
private readonly commandName;
|
|
22
|
-
private readonly logger;
|
|
23
|
-
private readonly onConcurrencyRecommendation?;
|
|
24
|
-
/**
|
|
25
|
-
* Długość okna profilowania w ms (1 minuta)
|
|
26
|
-
*/
|
|
27
|
-
private readonly PROFILING_WINDOW_MS;
|
|
28
|
-
/**
|
|
29
|
-
* Timestamp rozpoczęcia aktualnego okna profilowania
|
|
30
|
-
*/
|
|
31
|
-
private profilingWindowStartTime;
|
|
32
|
-
/**
|
|
33
|
-
* Licznik ukończonych jobów w aktualnym oknie
|
|
34
|
-
*/
|
|
35
|
-
private completedCount;
|
|
36
|
-
/**
|
|
37
|
-
* Licznik nieudanych jobów w aktualnym oknie
|
|
38
|
-
*/
|
|
39
|
-
private failedCount;
|
|
40
|
-
/**
|
|
41
|
-
* Licznik aktywnie przetwarzanych jobów (lokalny counter)
|
|
42
|
-
*/
|
|
43
|
-
private activeCount;
|
|
44
|
-
/**
|
|
45
|
-
* Czasy przetwarzania jobów w aktualnym oknie (ms)
|
|
46
|
-
*/
|
|
47
|
-
private processingTimes;
|
|
48
|
-
/**
|
|
49
|
-
* Historia średnich wartości activeCount dla analizy trendów
|
|
50
|
-
* Zbierana przy każdym evencie completed/failed
|
|
51
|
-
*/
|
|
52
|
-
private activeCountHistory;
|
|
53
|
-
private readonly maxActiveCountHistory;
|
|
54
|
-
constructor(commandName: string, logger: ILogger, onConcurrencyRecommendation?: ((recommendation: ConcurrencyRecommendation) => void) | undefined);
|
|
55
|
-
/**
|
|
56
|
-
* Wywołane gdy job zostaje aktywowany (rozpoczęty)
|
|
57
|
-
* @param jobId - ID joba
|
|
58
|
-
*/
|
|
59
|
-
onJobActive(jobId: string): void;
|
|
60
|
-
/**
|
|
61
|
-
* Wywołane gdy job zostaje ukończony pomyślnie
|
|
62
|
-
* @param jobId - ID joba
|
|
63
|
-
* @param processingTimeMs - Czas przetwarzania w ms
|
|
64
|
-
*/
|
|
65
|
-
onJobCompleted(jobId: string, processingTimeMs: number): void;
|
|
66
|
-
/**
|
|
67
|
-
* Wywołane gdy job kończy się niepowodzeniem
|
|
68
|
-
* @param jobId - ID joba
|
|
69
|
-
*/
|
|
70
|
-
onJobFailed(jobId: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Sprawdza czy minęło okno profilowania (1 minuta)
|
|
73
|
-
* Jeśli tak, loguje podsumowanie, analizuje i resetuje
|
|
74
|
-
*/
|
|
75
|
-
private checkWindowReset;
|
|
76
|
-
/**
|
|
77
|
-
* Wyświetla podsumowanie okna, analizuje metryki i resetuje liczniki
|
|
78
|
-
*/
|
|
79
|
-
private displayMetricsAndReset;
|
|
80
|
-
/**
|
|
81
|
-
* Oblicza statystyki dla aktualnego okna profilowania
|
|
82
|
-
*/
|
|
83
|
-
private calculateWindowStats;
|
|
84
|
-
/**
|
|
85
|
-
* Analizuje metryki i rekomenduje zmianę concurrency
|
|
86
|
-
* Bazuje na activeCount zamiast waiting (event-driven)
|
|
87
|
-
*/
|
|
88
|
-
private analyzeAndRecommendConcurrency;
|
|
89
|
-
/**
|
|
90
|
-
* Zapisuje snapshot activeCount do historii dla analizy trendów
|
|
91
|
-
*/
|
|
92
|
-
private recordActiveCountSnapshot;
|
|
93
|
-
/**
|
|
94
|
-
* Resetuje okno profilowania - czyści wszystkie zebrane metryki
|
|
95
|
-
*/
|
|
96
|
-
private resetProfilingWindow;
|
|
97
|
-
}
|
|
98
|
-
export {};
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Zbiera metryki workera w trybie event-driven
|
|
5
|
-
* Resetuje dane co 1 minutę (okno profilowania)
|
|
6
|
-
* Nie używa setInterval - bazuje na eventach jobów
|
|
7
|
-
*/
|
|
8
|
-
class WorkerMetricsCollector {
|
|
9
|
-
constructor(commandName, logger, onConcurrencyRecommendation) {
|
|
10
|
-
this.commandName = commandName;
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
this.onConcurrencyRecommendation = onConcurrencyRecommendation;
|
|
13
|
-
/**
|
|
14
|
-
* Długość okna profilowania w ms (1 minuta)
|
|
15
|
-
*/
|
|
16
|
-
this.PROFILING_WINDOW_MS = 60000;
|
|
17
|
-
/**
|
|
18
|
-
* Timestamp rozpoczęcia aktualnego okna profilowania
|
|
19
|
-
*/
|
|
20
|
-
this.profilingWindowStartTime = 0;
|
|
21
|
-
/**
|
|
22
|
-
* Licznik ukończonych jobów w aktualnym oknie
|
|
23
|
-
*/
|
|
24
|
-
this.completedCount = 0;
|
|
25
|
-
/**
|
|
26
|
-
* Licznik nieudanych jobów w aktualnym oknie
|
|
27
|
-
*/
|
|
28
|
-
this.failedCount = 0;
|
|
29
|
-
/**
|
|
30
|
-
* Licznik aktywnie przetwarzanych jobów (lokalny counter)
|
|
31
|
-
*/
|
|
32
|
-
this.activeCount = 0;
|
|
33
|
-
/**
|
|
34
|
-
* Czasy przetwarzania jobów w aktualnym oknie (ms)
|
|
35
|
-
*/
|
|
36
|
-
this.processingTimes = [];
|
|
37
|
-
/**
|
|
38
|
-
* Historia średnich wartości activeCount dla analizy trendów
|
|
39
|
-
* Zbierana przy każdym evencie completed/failed
|
|
40
|
-
*/
|
|
41
|
-
this.activeCountHistory = [];
|
|
42
|
-
this.maxActiveCountHistory = 30;
|
|
43
|
-
// Zainicjuj okno profilowania
|
|
44
|
-
this.profilingWindowStartTime = Date.now();
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Wywołane gdy job zostaje aktywowany (rozpoczęty)
|
|
48
|
-
* @param jobId - ID joba
|
|
49
|
-
*/
|
|
50
|
-
onJobActive(jobId) {
|
|
51
|
-
this.activeCount++;
|
|
52
|
-
this.logger.debug('Job aktywowany - metryki', {
|
|
53
|
-
commandName: this.commandName,
|
|
54
|
-
jobId,
|
|
55
|
-
activeCount: this.activeCount,
|
|
56
|
-
timestamp: new Date().toISOString(),
|
|
57
|
-
});
|
|
58
|
-
// Sprawdź czy minęło okno profilowania
|
|
59
|
-
this.checkWindowReset();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Wywołane gdy job zostaje ukończony pomyślnie
|
|
63
|
-
* @param jobId - ID joba
|
|
64
|
-
* @param processingTimeMs - Czas przetwarzania w ms
|
|
65
|
-
*/
|
|
66
|
-
onJobCompleted(jobId, processingTimeMs) {
|
|
67
|
-
this.activeCount--;
|
|
68
|
-
this.completedCount++;
|
|
69
|
-
this.processingTimes.push(processingTimeMs);
|
|
70
|
-
// Zapisz snapshot activeCount dla analizy trendów
|
|
71
|
-
this.recordActiveCountSnapshot();
|
|
72
|
-
this.logger.debug('Job ukończony - metryki', {
|
|
73
|
-
commandName: this.commandName,
|
|
74
|
-
jobId,
|
|
75
|
-
processingTimeMs,
|
|
76
|
-
activeCount: this.activeCount,
|
|
77
|
-
completedCount: this.completedCount,
|
|
78
|
-
timestamp: new Date().toISOString(),
|
|
79
|
-
});
|
|
80
|
-
// Sprawdź czy minęło okno profilowania
|
|
81
|
-
this.checkWindowReset();
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Wywołane gdy job kończy się niepowodzeniem
|
|
85
|
-
* @param jobId - ID joba
|
|
86
|
-
*/
|
|
87
|
-
onJobFailed(jobId) {
|
|
88
|
-
this.activeCount--;
|
|
89
|
-
this.failedCount++;
|
|
90
|
-
// Zapisz snapshot activeCount dla analizy trendów
|
|
91
|
-
this.recordActiveCountSnapshot();
|
|
92
|
-
this.logger.debug('Job nieudany - metryki', {
|
|
93
|
-
commandName: this.commandName,
|
|
94
|
-
jobId,
|
|
95
|
-
activeCount: this.activeCount,
|
|
96
|
-
failedCount: this.failedCount,
|
|
97
|
-
timestamp: new Date().toISOString(),
|
|
98
|
-
});
|
|
99
|
-
// Sprawdź czy minęło okno profilowania
|
|
100
|
-
this.checkWindowReset();
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Sprawdza czy minęło okno profilowania (1 minuta)
|
|
104
|
-
* Jeśli tak, loguje podsumowanie, analizuje i resetuje
|
|
105
|
-
*/
|
|
106
|
-
checkWindowReset() {
|
|
107
|
-
const windowElapsedMs = Date.now() - this.profilingWindowStartTime;
|
|
108
|
-
if (windowElapsedMs >= this.PROFILING_WINDOW_MS) {
|
|
109
|
-
this.displayMetricsAndReset();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Wyświetla podsumowanie okna, analizuje metryki i resetuje liczniki
|
|
114
|
-
*/
|
|
115
|
-
displayMetricsAndReset() {
|
|
116
|
-
const windowStats = this.calculateWindowStats();
|
|
117
|
-
this.logger.log(`Podsumowanie okna profilowania ${this.commandName}`, windowStats);
|
|
118
|
-
// Jeśli mamy wystarczająco danych (przynajmniej 5 jobów), wygeneruj rekomendację
|
|
119
|
-
if (this.completedCount >= 5 && this.activeCountHistory.length >= 5) {
|
|
120
|
-
const recommendation = this.analyzeAndRecommendConcurrency();
|
|
121
|
-
this.logger.log(`Rekomendacja concurrency (koniec okna) ${this.commandName}`, recommendation);
|
|
122
|
-
if (recommendation.shouldAdjust && this.onConcurrencyRecommendation) {
|
|
123
|
-
this.onConcurrencyRecommendation(recommendation);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.logger.debug('Za mało danych dla rekomendacji concurrency', {
|
|
128
|
-
commandName: this.commandName,
|
|
129
|
-
completedCount: this.completedCount,
|
|
130
|
-
activeCountHistorySize: this.activeCountHistory.length,
|
|
131
|
-
timestamp: new Date().toISOString(),
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
// Reset okna profilowania
|
|
135
|
-
this.resetProfilingWindow();
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Oblicza statystyki dla aktualnego okna profilowania
|
|
139
|
-
*/
|
|
140
|
-
calculateWindowStats() {
|
|
141
|
-
const windowDurationMs = Date.now() - this.profilingWindowStartTime;
|
|
142
|
-
const windowDurationSec = windowDurationMs / 1000;
|
|
143
|
-
// Oblicz średni czas przetwarzania
|
|
144
|
-
const avgProcessingTimeMs = this.processingTimes.length > 0
|
|
145
|
-
? this.processingTimes.reduce((sum, time) => sum + time, 0) / this.processingTimes.length
|
|
146
|
-
: 0;
|
|
147
|
-
// Oblicz przepustowość
|
|
148
|
-
const jobsPerSecond = windowDurationSec > 0 ? this.completedCount / windowDurationSec : 0;
|
|
149
|
-
const jobsPerMinute = jobsPerSecond * 60;
|
|
150
|
-
return {
|
|
151
|
-
commandName: this.commandName,
|
|
152
|
-
windowDurationMs: Math.round(windowDurationMs),
|
|
153
|
-
completedJobs: this.completedCount,
|
|
154
|
-
failedJobs: this.failedCount,
|
|
155
|
-
currentActiveJobs: this.activeCount,
|
|
156
|
-
avgProcessingTimeMs: Math.round(avgProcessingTimeMs),
|
|
157
|
-
jobsPerSecond: Number(jobsPerSecond.toFixed(1)),
|
|
158
|
-
jobsPerMinute: Math.round(jobsPerMinute),
|
|
159
|
-
timestamp: new Date().toISOString(),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Analizuje metryki i rekomenduje zmianę concurrency
|
|
164
|
-
* Bazuje na activeCount zamiast waiting (event-driven)
|
|
165
|
-
*/
|
|
166
|
-
analyzeAndRecommendConcurrency() {
|
|
167
|
-
const currentMetrics = {
|
|
168
|
-
activeCount: this.activeCount,
|
|
169
|
-
completedCount: this.completedCount,
|
|
170
|
-
avgProcessingTimeMs: Math.round(this.processingTimes.reduce((sum, time) => sum + time, 0) / this.processingTimes.length),
|
|
171
|
-
};
|
|
172
|
-
// Oblicz średnią activeCount z historii
|
|
173
|
-
const avgActiveCount = this.activeCountHistory.reduce((sum, count) => sum + count, 0) /
|
|
174
|
-
this.activeCountHistory.length;
|
|
175
|
-
// Analiza trendu activeCount
|
|
176
|
-
// Jeśli activeCount konsekwentnie wysoki → worker jest pod obciążeniem → zwiększ concurrency
|
|
177
|
-
// Jeśli activeCount konsekwentnie niski → worker ma nadmiar → zmniejsz concurrency
|
|
178
|
-
const highActiveThreshold = 0.8; // 80% historii z wysokim activeCount
|
|
179
|
-
const lowActiveThreshold = 0.3; // 30% historii z niskim activeCount
|
|
180
|
-
const highActiveRatio = this.activeCountHistory.filter((count) => count >= avgActiveCount * 0.9).length /
|
|
181
|
-
this.activeCountHistory.length;
|
|
182
|
-
const lowActiveRatio = this.activeCountHistory.filter((count) => count <= avgActiveCount * 0.3).length /
|
|
183
|
-
this.activeCountHistory.length;
|
|
184
|
-
// Warunki zwiększenia concurrency
|
|
185
|
-
if (highActiveRatio >= highActiveThreshold && avgActiveCount >= 5) {
|
|
186
|
-
return {
|
|
187
|
-
shouldAdjust: true,
|
|
188
|
-
direction: 'increase',
|
|
189
|
-
reason: `Wysoki activeCount: średnia=${avgActiveCount.toFixed(1)}, ratio=${(highActiveRatio * 100).toFixed(0)}%`,
|
|
190
|
-
currentMetrics,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// Warunki zmniejszenia concurrency
|
|
194
|
-
if (lowActiveRatio >= lowActiveThreshold && avgActiveCount >= 1) {
|
|
195
|
-
return {
|
|
196
|
-
shouldAdjust: true,
|
|
197
|
-
direction: 'decrease',
|
|
198
|
-
reason: `Niski activeCount: średnia=${avgActiveCount.toFixed(1)}, ratio=${(lowActiveRatio * 100).toFixed(0)}%`,
|
|
199
|
-
currentMetrics,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
// Stabilna sytuacja - brak rekomendacji
|
|
203
|
-
return {
|
|
204
|
-
shouldAdjust: false,
|
|
205
|
-
direction: 'none',
|
|
206
|
-
reason: `Stabilne activeCount: średnia=${avgActiveCount.toFixed(1)}`,
|
|
207
|
-
currentMetrics,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Zapisuje snapshot activeCount do historii dla analizy trendów
|
|
212
|
-
*/
|
|
213
|
-
recordActiveCountSnapshot() {
|
|
214
|
-
this.activeCountHistory.push(this.activeCount);
|
|
215
|
-
// Ogranicz rozmiar historii
|
|
216
|
-
if (this.activeCountHistory.length > this.maxActiveCountHistory) {
|
|
217
|
-
this.activeCountHistory.shift();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Resetuje okno profilowania - czyści wszystkie zebrane metryki
|
|
222
|
-
*/
|
|
223
|
-
resetProfilingWindow() {
|
|
224
|
-
this.logger.log(`Reset okna profilowania ${this.commandName}`, {
|
|
225
|
-
commandName: this.commandName,
|
|
226
|
-
windowDurationMs: Date.now() - this.profilingWindowStartTime,
|
|
227
|
-
completedJobs: this.completedCount,
|
|
228
|
-
failedJobs: this.failedCount,
|
|
229
|
-
timestamp: new Date().toISOString(),
|
|
230
|
-
});
|
|
231
|
-
// Reset liczników
|
|
232
|
-
this.completedCount = 0;
|
|
233
|
-
this.failedCount = 0;
|
|
234
|
-
this.processingTimes = [];
|
|
235
|
-
this.activeCountHistory = [];
|
|
236
|
-
// activeCount NIE resetujemy - to bieżąca liczba aktywnych jobów
|
|
237
|
-
// Rozpocznij nowe okno
|
|
238
|
-
this.profilingWindowStartTime = Date.now();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.default = WorkerMetricsCollector;
|
|
242
|
-
//# sourceMappingURL=worker-metrics-collector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-metrics-collector.js","sourceRoot":"","sources":["../../../src/command-bus/worker/worker-metrics-collector.ts"],"names":[],"mappings":";;AAgBA;;;;GAIG;AACH,MAAqB,sBAAsB;IAsCzC,YACmB,WAAmB,EACnB,MA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K,yBAAyB;QAC/B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE/C,4BAA4B;QAC5B,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAChE,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,2BAA2B,IAAI,CAAC,WAAW,EAAE,EAAE;YAC7D,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,wBAAwB;YAC5D,aAAa,EAAE,IAAI,CAAC,cAAc;YAClC,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;QAEH,kBAAkB;QAClB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC7B,iEAAiE;QAEjE,uBAAuB;QACvB,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7C,CAAC;CACF;AArSD,yCAqSC"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'bullmq';
|
|
2
|
-
import type { Redis } from 'ioredis';
|
|
3
|
-
import type { ILogger } from '../../shared/types';
|
|
4
|
-
import type JobProcessor from '../job/job-processor';
|
|
5
|
-
/**
|
|
6
|
-
* Zarządza workerami BullMQ dla obsługi komend
|
|
7
|
-
*/
|
|
8
|
-
export default class WorkerOrchestrator {
|
|
9
|
-
private readonly redisConnection;
|
|
10
|
-
private readonly jobProcessor;
|
|
11
|
-
private readonly defaultConcurrency;
|
|
12
|
-
private readonly maxAttempts;
|
|
13
|
-
private readonly logger;
|
|
14
|
-
/**
|
|
15
|
-
* Workery BullMQ dla obsługi komend
|
|
16
|
-
*/
|
|
17
|
-
private workers;
|
|
18
|
-
/**
|
|
19
|
-
* Collectory metryk dla każdego workera
|
|
20
|
-
*/
|
|
21
|
-
private metricsCollectors;
|
|
22
|
-
/**
|
|
23
|
-
* Timestamp ostatniej zmiany concurrency per-worker (dla cooldown 30s)
|
|
24
|
-
*/
|
|
25
|
-
private lastConcurrencyChange;
|
|
26
|
-
/**
|
|
27
|
-
* Cooldown między zmianami concurrency (30s)
|
|
28
|
-
*/
|
|
29
|
-
private readonly concurrencyCooldownMs;
|
|
30
|
-
/**
|
|
31
|
-
* Współczynnik zwiększenia concurrency (+20%)
|
|
32
|
-
*/
|
|
33
|
-
private readonly CONCURRENCY_INCREASE_FACTOR;
|
|
34
|
-
/**
|
|
35
|
-
* Współczynnik zmniejszenia concurrency (-20%)
|
|
36
|
-
*/
|
|
37
|
-
private readonly CONCURRENCY_DECREASE_FACTOR;
|
|
38
|
-
constructor(redisConnection: Redis, jobProcessor: JobProcessor, defaultConcurrency: number, maxAttempts: number, logger: ILogger);
|
|
39
|
-
/**
|
|
40
|
-
* Rejestruje handler dla komendy i tworzy workera
|
|
41
|
-
* @param commandName - Nazwa komendy
|
|
42
|
-
*/
|
|
43
|
-
registerWorker(commandName: string): void;
|
|
44
|
-
/**
|
|
45
|
-
* Konfiguruje event handlery dla workera
|
|
46
|
-
*/
|
|
47
|
-
private setupWorkerEventHandlers;
|
|
48
|
-
/**
|
|
49
|
-
* Pobiera workera dla danego typu komendy
|
|
50
|
-
* @param commandName - Nazwa komendy
|
|
51
|
-
*/
|
|
52
|
-
getWorker(commandName: string): Worker | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Zamyka wszystkie workery i czyści collectory metryk
|
|
55
|
-
*/
|
|
56
|
-
closeAll(): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Dynamicznie dostosowuje concurrency workera na podstawie metryk
|
|
59
|
-
* Zmiana: +/-20% za każdym razem, z cooldown 30s
|
|
60
|
-
* Limity: min 10, max 2000
|
|
61
|
-
*/
|
|
62
|
-
adjustConcurrency(commandName: string, direction: 'increase' | 'decrease', reason: string): void;
|
|
63
|
-
/**
|
|
64
|
-
* Zwraca statystyki workerów (dla diagnostyki)
|
|
65
|
-
*/
|
|
66
|
-
getWorkerStats(): {
|
|
67
|
-
activeWorkersCount: number;
|
|
68
|
-
workerNames: string[];
|
|
69
|
-
};
|
|
70
|
-
}
|