@imqueue/core 2.0.17 → 2.0.18
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/package.json +1 -1
- package/src/RedisQueue.js +13 -23
- package/debug_getter.d.ts +0 -9
- package/debug_listener.d.ts +0 -1
package/package.json
CHANGED
package/src/RedisQueue.js
CHANGED
|
@@ -57,8 +57,6 @@ exports.DEFAULT_IMQ_OPTIONS = {
|
|
|
57
57
|
safeDeliveryTtl: 5000,
|
|
58
58
|
useGzip: false,
|
|
59
59
|
watcherCheckDelay: 5000,
|
|
60
|
-
verbose: false,
|
|
61
|
-
verboseExtended: false,
|
|
62
60
|
};
|
|
63
61
|
exports.IMQ_SHUTDOWN_TIMEOUT = +(process.env.IMQ_SHUTDOWN_TIMEOUT || 1000);
|
|
64
62
|
/**
|
|
@@ -174,16 +172,9 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
174
172
|
this.redisKey = `${this.options.host}:${this.options.port}`;
|
|
175
173
|
this.verbose(`Initializing queue on ${this.options.host}:${this.options.port} with prefix ${this.options.prefix} and safeDelivery = ${this.options.safeDelivery}, and safeDeliveryTtl = ${this.options.safeDeliveryTtl}, and watcherCheckDelay = ${this.options.watcherCheckDelay}, and useGzip = ${this.options.useGzip}`);
|
|
176
174
|
}
|
|
177
|
-
verbose(message
|
|
178
|
-
if (sensitiveOnly && !this.options.verboseExtended) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
175
|
+
verbose(message) {
|
|
181
176
|
if (this.options.verbose) {
|
|
182
|
-
|
|
183
|
-
const fullText = this.options.verboseExtended
|
|
184
|
-
? `${text}${sensitiveMessage}`
|
|
185
|
-
: text;
|
|
186
|
-
this.logger.info(fullText);
|
|
177
|
+
this.logger.info(`[IMQ-CORE][${this.name}]: ${message}`);
|
|
187
178
|
}
|
|
188
179
|
}
|
|
189
180
|
/**
|
|
@@ -214,7 +205,7 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
214
205
|
if (ch === fcn && typeof handler === 'function') {
|
|
215
206
|
handler(JSON.parse(message));
|
|
216
207
|
}
|
|
217
|
-
this.verbose(`Received message from ${ch} channel
|
|
208
|
+
this.verbose(`Received message from ${ch} channel, data: ${JSON.stringify(message)}`);
|
|
218
209
|
});
|
|
219
210
|
this.verbose(`Subscribed to ${channel} channel`);
|
|
220
211
|
}
|
|
@@ -227,12 +218,12 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
227
218
|
if (this.subscription) {
|
|
228
219
|
this.verbose('Initialize unsubscribing...');
|
|
229
220
|
if (this.subscriptionName) {
|
|
230
|
-
|
|
221
|
+
this.subscription.unsubscribe(`${this.options.prefix}:${this.subscriptionName}`);
|
|
231
222
|
this.verbose(`Unsubscribed from ${this.subscriptionName} channel`);
|
|
232
223
|
}
|
|
233
224
|
this.subscription.removeAllListeners();
|
|
234
225
|
this.subscription.disconnect(false);
|
|
235
|
-
|
|
226
|
+
this.subscription.quit();
|
|
236
227
|
}
|
|
237
228
|
this.subscriptionName = undefined;
|
|
238
229
|
this.subscription = undefined;
|
|
@@ -255,7 +246,8 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
255
246
|
const jsonData = JSON.stringify(data);
|
|
256
247
|
const name = toName || this.name;
|
|
257
248
|
await this.writer.publish(`${this.options.prefix}:${name}`, jsonData);
|
|
258
|
-
this.verbose(`Published message to ${name} channel
|
|
249
|
+
this.verbose(`Published message to ${name} channel, data: ${jsonData}
|
|
250
|
+
`);
|
|
259
251
|
}
|
|
260
252
|
/**
|
|
261
253
|
* Initializes and starts current queue routines
|
|
@@ -336,7 +328,6 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
336
328
|
const data = { id, message, from: this.name };
|
|
337
329
|
const key = `${this.options.prefix}:${toQueue}`;
|
|
338
330
|
const packet = this.pack(data);
|
|
339
|
-
this.verbose('Message send', `: ${packet}`, true);
|
|
340
331
|
const cb = (error, op) => {
|
|
341
332
|
// istanbul ignore next
|
|
342
333
|
if (error) {
|
|
@@ -347,10 +338,10 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
347
338
|
}
|
|
348
339
|
};
|
|
349
340
|
if (delay) {
|
|
350
|
-
|
|
341
|
+
this.writer.zadd(`${key}:delayed`, Date.now() + delay, packet, (err) => {
|
|
351
342
|
// istanbul ignore next
|
|
352
|
-
if (
|
|
353
|
-
cb(
|
|
343
|
+
if (err) {
|
|
344
|
+
cb(err, 'ZADD');
|
|
354
345
|
return;
|
|
355
346
|
}
|
|
356
347
|
this.writer.set(`${key}:${id}:ttl`, '', 'PX', delay, 'NX', (err) => {
|
|
@@ -363,7 +354,7 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
363
354
|
});
|
|
364
355
|
}
|
|
365
356
|
else {
|
|
366
|
-
|
|
357
|
+
this.writer.lpush(key, packet, (err) => {
|
|
367
358
|
// istanbul ignore next
|
|
368
359
|
if (err) {
|
|
369
360
|
cb(err, 'LPUSH');
|
|
@@ -383,7 +374,7 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
383
374
|
if (this.reader) {
|
|
384
375
|
this.verbose('Destroying reader...');
|
|
385
376
|
this.reader.removeAllListeners();
|
|
386
|
-
|
|
377
|
+
this.reader.quit();
|
|
387
378
|
this.reader.disconnect(false);
|
|
388
379
|
delete this.reader;
|
|
389
380
|
}
|
|
@@ -724,7 +715,6 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
724
715
|
const { id, message, from } = this.unpack(data);
|
|
725
716
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
726
717
|
this.emit('message', message, id, from);
|
|
727
|
-
this.verbose('Message received', `: ${data}`, true);
|
|
728
718
|
}
|
|
729
719
|
catch (err) {
|
|
730
720
|
// istanbul ignore next
|
|
@@ -826,7 +816,7 @@ class RedisQueue extends events_1.EventEmitter {
|
|
|
826
816
|
*/
|
|
827
817
|
async onWatchMessage(...args) {
|
|
828
818
|
try {
|
|
829
|
-
const key = (
|
|
819
|
+
const key = (args.pop() || '').split(':');
|
|
830
820
|
if (key.pop() !== 'ttl') {
|
|
831
821
|
return;
|
|
832
822
|
}
|
package/debug_getter.d.ts
DELETED
package/debug_listener.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|