@seidor-cloud-produtos/orbit-backend-lib 2.0.20 → 2.0.22
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.
|
@@ -5,10 +5,9 @@ import { RabbitMQScaledJobOptions } from './types';
|
|
|
5
5
|
export declare class RabbitMQScaledJobRunner<T = any> {
|
|
6
6
|
private readonly amqpQueue;
|
|
7
7
|
private readonly queueName;
|
|
8
|
-
private readonly vHost;
|
|
9
8
|
private readonly handler;
|
|
10
9
|
private readonly options;
|
|
11
|
-
constructor(amqpQueue: AmqpQueue, queueName: string,
|
|
10
|
+
constructor(amqpQueue: AmqpQueue, queueName: string, handler: Handler, options: RabbitMQScaledJobOptions);
|
|
12
11
|
private handleError;
|
|
13
12
|
protected errorStrategy(getResult: AmqpQueueGetResult): Promise<void>;
|
|
14
13
|
private rejectTimeout;
|
|
@@ -6,13 +6,11 @@ const logger_in_memory_1 = tslib_1.__importDefault(require("../logger/logger-in-
|
|
|
6
6
|
class RabbitMQScaledJobRunner {
|
|
7
7
|
amqpQueue;
|
|
8
8
|
queueName;
|
|
9
|
-
vHost;
|
|
10
9
|
handler;
|
|
11
10
|
options;
|
|
12
|
-
constructor(amqpQueue, queueName,
|
|
11
|
+
constructor(amqpQueue, queueName, handler, options) {
|
|
13
12
|
this.amqpQueue = amqpQueue;
|
|
14
13
|
this.queueName = queueName;
|
|
15
|
-
this.vHost = vHost;
|
|
16
14
|
this.handler = handler;
|
|
17
15
|
this.options = options;
|
|
18
16
|
}
|
|
@@ -43,9 +41,8 @@ class RabbitMQScaledJobRunner {
|
|
|
43
41
|
async run() {
|
|
44
42
|
let getResult = null;
|
|
45
43
|
let consumedMessages = 0;
|
|
46
|
-
const messagesToGet = this.
|
|
44
|
+
const messagesToGet = this.handler.getSimultaneity();
|
|
47
45
|
try {
|
|
48
|
-
await this.amqpQueue.connect(this.vHost);
|
|
49
46
|
while (consumedMessages < messagesToGet) {
|
|
50
47
|
try {
|
|
51
48
|
getResult = await this.amqpQueue.get(this.queueName, {
|
|
@@ -24,7 +24,7 @@ const runner_1 = require("./runner");
|
|
|
24
24
|
parse: vitest_1.vi.fn((raw) => ({ ok: true, msg: 'parsed' })),
|
|
25
25
|
};
|
|
26
26
|
onFinally = vitest_1.vi.fn();
|
|
27
|
-
runner = new runner_1.RabbitMQScaledJobRunner(amqpQueue, 'queue',
|
|
27
|
+
runner = new runner_1.RabbitMQScaledJobRunner(amqpQueue, 'queue', handler, options);
|
|
28
28
|
});
|
|
29
29
|
(0, vitest_1.it)('should connect, get, handle, ack and close (happy path)', async () => {
|
|
30
30
|
const rawMessage = { content: Buffer.from('msg') };
|
|
@@ -51,7 +51,9 @@ const runner_1 = require("./runner");
|
|
|
51
51
|
const rawMessage = { content: Buffer.from('msg') };
|
|
52
52
|
const channel = {};
|
|
53
53
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
54
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
54
|
+
handler.handle = vitest_1.vi.fn(() => {
|
|
55
|
+
throw new Error('fail');
|
|
56
|
+
});
|
|
55
57
|
await runner.run();
|
|
56
58
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, true);
|
|
57
59
|
});
|
|
@@ -60,7 +62,9 @@ const runner_1 = require("./runner");
|
|
|
60
62
|
const rawMessage = { content: Buffer.from('msg') };
|
|
61
63
|
const channel = {};
|
|
62
64
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
63
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
65
|
+
handler.handle = vitest_1.vi.fn(() => {
|
|
66
|
+
throw new Error('fail');
|
|
67
|
+
});
|
|
64
68
|
await runner.run();
|
|
65
69
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, false);
|
|
66
70
|
});
|
|
@@ -106,7 +110,9 @@ const runner_1 = require("./runner");
|
|
|
106
110
|
const rawMessage = { content: Buffer.from('msg') };
|
|
107
111
|
const channel = {};
|
|
108
112
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
109
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
113
|
+
handler.handle = vitest_1.vi.fn(() => {
|
|
114
|
+
throw new Error('fail');
|
|
115
|
+
});
|
|
110
116
|
await runner.run();
|
|
111
117
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, false);
|
|
112
118
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export type ErrorStrategy =
|
|
1
|
+
export type ErrorStrategy = 'nack-dlq' | 'nack-requeue';
|
|
2
2
|
export type RabbitMQScaledJobOptions = {
|
|
3
3
|
parse: (raw: any) => any;
|
|
4
4
|
manualAck: boolean;
|
|
5
5
|
errorStrategy: ErrorStrategy;
|
|
6
6
|
timeoutMs: number;
|
|
7
|
-
numberOfMessagesToGet?: number;
|
|
8
7
|
};
|