@autofleet/rabbit 2.0.4-beta1 → 2.0.4-beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -46,15 +46,16 @@ const defaultOptions = {
46
46
  };
47
47
  const assertExchangeFanout = (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
48
48
  const callbackWithTimeout = (callback, args, timeout, timeoutMessage = 'Timeout while ack message') => __awaiter(void 0, void 0, void 0, function* () {
49
- yield new bluebird.Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
50
- try {
51
- yield callback(...args);
52
- return resolve();
53
- }
54
- catch (e) {
55
- return reject(e);
56
- }
57
- })).timeout(timeout, timeoutMessage);
49
+ const callbackPromise = new bluebird.Promise(callback(...args));
50
+ Promise.race([
51
+ callbackPromise,
52
+ new Promise((resolve, reject) => {
53
+ setTimeout(() => {
54
+ callbackPromise.cancel();
55
+ reject(timeoutMessage);
56
+ }, timeout);
57
+ }),
58
+ ]);
58
59
  });
59
60
  const connectionCreatedConst = 'connectionCreated';
60
61
  class RabbitMq {
@@ -204,7 +205,7 @@ class RabbitMq {
204
205
  yield c.assertQueue(queue);
205
206
  yield c.prefetch(limit, true);
206
207
  return Promise.all([
207
- c.consume(queue, (msg) => {
208
+ c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
208
209
  outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
209
210
  if (optionsWithDefaults.timeout) {
210
211
  const args = [
@@ -212,12 +213,17 @@ class RabbitMq {
212
213
  this.ack(channel),
213
214
  this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
214
215
  ];
215
- callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
216
+ try {
217
+ yield callbackWithTimeout(callback, args, optionsWithDefaults.timeout, optionsWithDefaults.timeoutMessage);
218
+ }
219
+ catch (e) {
220
+ this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
221
+ }
216
222
  }
217
223
  else {
218
224
  callback(RabbitMq.parseMsg(msg), this.ack(channel), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
219
225
  }
220
- }),
226
+ })),
221
227
  ]);
222
228
  }));
223
229
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.0.4-beta1",
3
+ "version": "2.0.4-beta2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -37,14 +37,18 @@ const defaultOptions = {
37
37
 
38
38
  const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
39
39
 
40
- const callbackWithTimeout = async (callback: any, args: any[], timeout: number, timeoutMessage = 'Timeout while ack message') => Promise.race([
41
- new Promise(callback(...args)),
42
- new Promise((resolve, reject) => {
43
- setTimeout(() => {
44
- reject(timeoutMessage);
45
- }, timeout);
46
- }),
47
- ]);
40
+ const callbackWithTimeout = async (callback: any, args: any[], timeout: number, timeoutMessage = 'Timeout while ack message') => {
41
+ const callbackPromise = new bluebird.Promise(callback(...args));
42
+ Promise.race([
43
+ callbackPromise,
44
+ new Promise((resolve, reject) => {
45
+ setTimeout(() => {
46
+ callbackPromise.cancel();
47
+ reject(timeoutMessage);
48
+ }, timeout);
49
+ }),
50
+ ]);
51
+ };
48
52
 
49
53
  const connectionCreatedConst = 'connectionCreated';
50
54
  class RabbitMq implements IAfRabbitMq {