@palmetto/pubsub 2.2.7 → 2.2.8

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.
@@ -117,10 +117,10 @@ class RabbitMqPublisher {
117
117
  timestamp: Date.now(),
118
118
  persistent: true,
119
119
  };
120
- const oks = yield Promise.all(messages.map((message) => sender(Buffer.from(message, "utf8"), options)));
120
+ const oks = yield Promise.allSettled(messages.map((message) => sender(Buffer.from(message, "utf8"), options)));
121
121
  const failedMessages = oks
122
122
  .map((ok, index) => ({ ok, index }))
123
- .filter(({ ok }) => !ok)
123
+ .filter(({ ok }) => ok.status === "rejected")
124
124
  .map(({ index }) => messages[index]);
125
125
  if (failedMessages.length > 0) {
126
126
  const allOrSome = failedMessages.length === messages.length ? "all" : "some";
@@ -6,12 +6,13 @@ import { RabbitMqConnection } from "./connection.js";
6
6
  declare class SubscribedMessage {
7
7
  private readonly owner;
8
8
  private readonly logger;
9
+ private readonly queueName;
9
10
  readonly config: RabbitQueueExchangeConfiguration;
10
11
  readonly onMessage: (s: string, context: RabbitMqMessageContext) => Promise<MessageResult> | MessageResult;
11
12
  stop?: StopSubscribe | undefined;
12
13
  channel?: ChannelWrapper;
13
14
  busy: number;
14
- constructor(owner: RabbitMqSubscriber, logger: Logger, config: RabbitQueueExchangeConfiguration, onMessage: (s: string, context: RabbitMqMessageContext) => Promise<MessageResult> | MessageResult, stop?: StopSubscribe | undefined);
15
+ constructor(owner: RabbitMqSubscriber, logger: Logger, queueName: string, config: RabbitQueueExchangeConfiguration, onMessage: (s: string, context: RabbitMqMessageContext) => Promise<MessageResult> | MessageResult, stop?: StopSubscribe | undefined);
15
16
  stopSubscribe(): Promise<void>;
16
17
  }
17
18
  export declare class RabbitMqSubscriber implements SubscriberProvider {
@@ -17,9 +17,10 @@ const connection_js_1 = require("./connection.js");
17
17
  const create_log_error_payload_js_1 = require("../create-log-error-payload.js");
18
18
  const dd_trace_api_1 = require("dd-trace-api");
19
19
  class SubscribedMessage {
20
- constructor(owner, logger, config, onMessage, stop) {
20
+ constructor(owner, logger, queueName, config, onMessage, stop) {
21
21
  this.owner = owner;
22
22
  this.logger = logger;
23
+ this.queueName = queueName;
23
24
  this.config = config;
24
25
  this.onMessage = onMessage;
25
26
  this.stop = stop;
@@ -34,16 +35,16 @@ class SubscribedMessage {
34
35
  this.stop = undefined;
35
36
  this.owner.removeSubscriber(this);
36
37
  if (this.busy) {
37
- (_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "RabbitMq subscriber waiting for handler to finish");
38
- const start = new Date().valueOf();
38
+ (_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `RabbitMq subscriber waiting for ${this.queueName} handler to finish`);
39
+ const start = Date.now();
39
40
  const waitDelay = 5;
40
- let busyCheck = 1000 / waitDelay; // wait up to a second or so
41
+ let busyCheck = 5000 / waitDelay; // wait a few seconds before shutdown
41
42
  while (this.busy && busyCheck > 0) {
42
43
  yield new Promise((resolve) => setTimeout(resolve, waitDelay));
43
44
  busyCheck -= waitDelay;
44
45
  }
45
- const delay = new Date().valueOf() - start;
46
- (_d = (_c = this.logger).debug) === null || _d === void 0 ? void 0 : _d.call(_c, `RabbitMq subscriber waited ${delay}ms for handler to finish`);
46
+ const delay = Date.now() - start;
47
+ (_d = (_c = this.logger).debug) === null || _d === void 0 ? void 0 : _d.call(_c, `RabbitMq subscriber waited ${delay}ms for ${this.queueName} handler to finish`);
47
48
  }
48
49
  yield s();
49
50
  }
@@ -73,7 +74,7 @@ class RabbitMqSubscriber {
73
74
  if (subscribedMessage) {
74
75
  throw new errors_js_1.AlreadySubscribingError(queueName);
75
76
  }
76
- subscribedMessage = new SubscribedMessage(this, this.logger, config, onMessage);
77
+ subscribedMessage = new SubscribedMessage(this, this.logger, queueName, config, onMessage);
77
78
  this.subscribers.set(queueName, subscribedMessage);
78
79
  subscribedMessage.channel = this.connection.connection.createChannel({
79
80
  setup: (channel) => __awaiter(this, void 0, void 0, function* () {
@@ -84,9 +85,9 @@ class RabbitMqSubscriber {
84
85
  }
85
86
  close() {
86
87
  return __awaiter(this, void 0, void 0, function* () {
87
- for (const subscribedMessage of this.subscribers.values()) {
88
- yield subscribedMessage.stopSubscribe();
89
- }
88
+ yield Promise.all(this.subscribers
89
+ .values()
90
+ .map((subscribedMessage) => subscribedMessage.stopSubscribe()));
90
91
  this.subscribers.clear();
91
92
  });
92
93
  }
@@ -163,9 +164,10 @@ class RabbitMqSubscriber {
163
164
  this.logger.log(`RabbitMQ consumer started for ${queueName}`);
164
165
  // stop will cancel the subscriber
165
166
  subscribedMessage.stop = () => __awaiter(this, void 0, void 0, function* () {
166
- var _a, _b;
167
+ var _a, _b, _c, _d;
168
+ (_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `RabbitMQ consumer stopping for ${queueName}`);
167
169
  yield channel.close();
168
- (_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `RabbitMQ consumer stopped for ${queueName}`);
170
+ (_d = (_c = this.logger).debug) === null || _d === void 0 ? void 0 : _d.call(_c, `RabbitMQ consumer stopped for ${queueName}`);
169
171
  });
170
172
  });
171
173
  }
@@ -207,7 +209,7 @@ class RabbitMqSubscriber {
207
209
  timestamp: (_d = sentDates.firstSent) === null || _d === void 0 ? void 0 : _d.valueOf(),
208
210
  headers: {
209
211
  [RETRIES_HEADER]: retries + 1,
210
- [RETRYSENT_HEADER]: new Date().valueOf(),
212
+ [RETRYSENT_HEADER]: Date.now(),
211
213
  },
212
214
  }));
213
215
  if (ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palmetto/pubsub",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "main": "./dist/main.js",
5
5
  "scripts": {
6
6
  "lint": "yarn run -T eslint --fix ./src",