Skip to content

Commit b589937

Browse files
committed
fix: conflicts
2 parents ceee1ae + f0b42db commit b589937

File tree

1 file changed

+25
-52
lines changed

1 file changed

+25
-52
lines changed

src/RedisQueue.ts

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export const DEFAULT_IMQ_OPTIONS: IMQOptions = {
5656
safeDeliveryTtl: 5000,
5757
useGzip: false,
5858
watcherCheckDelay: 5000,
59-
verbose: false,
60-
verboseExtended: false,
6159
};
6260

6361
export const IMQ_SHUTDOWN_TIMEOUT = +(process.env.IMQ_SHUTDOWN_TIMEOUT || 1000);
@@ -95,7 +93,7 @@ export function intrand(min: number, max: number): number {
9593
*/
9694
// istanbul ignore next
9795
export function pack(data: any): string {
98-
return (gzip(JSON.stringify(data)) as Buffer).toString('binary');
96+
return gzip(JSON.stringify(data)).toString('binary');
9997
}
10098

10199
/**
@@ -106,9 +104,7 @@ export function pack(data: any): string {
106104
*/
107105
// istanbul ignore next
108106
export function unpack(data: string): any {
109-
return JSON.parse(
110-
(gunzip(Buffer.from(data, 'binary')) as Buffer).toString(),
111-
);
107+
return JSON.parse(gunzip(Buffer.from(data, 'binary')).toString());
112108
}
113109

114110
type RedisConnectionChannel = 'reader' | 'writer' | 'watcher' | 'subscription';
@@ -279,31 +275,17 @@ export class RedisQueue extends EventEmitter<EventMap>
279275

280276
this.verbose(`Initializing queue on ${
281277
this.options.host }:${
282-
this.options.port } with prefix ${
278+
this.options.port} with prefix ${
283279
this.options.prefix } and safeDelivery = ${
284280
this.options.safeDelivery }, and safeDeliveryTtl = ${
285281
this.options.safeDeliveryTtl }, and watcherCheckDelay = ${
286282
this.options.watcherCheckDelay }, and useGzip = ${
287283
this.options.useGzip }`);
288284
}
289285

290-
private verbose(
291-
message: string,
292-
sensitiveMessage?: string,
293-
sensitiveOnly?: boolean,
294-
): void {
295-
if (sensitiveOnly && !this.options.verboseExtended) {
296-
return;
297-
}
298-
286+
private verbose(message: string): void {
299287
if (this.options.verbose) {
300-
const text = `[IMQ-CORE][${ this.name }]: ${ message }`;
301-
const fullText = this.options.verboseExtended
302-
? `${ text }${ sensitiveMessage }`
303-
: text
304-
;
305-
306-
this.logger.info(fullText);
288+
this.logger.info(`[IMQ-CORE][${ this.name }]: ${ message }`);
307289
}
308290
}
309291

@@ -347,9 +329,9 @@ export class RedisQueue extends EventEmitter<EventMap>
347329
handler(JSON.parse(message) as unknown as JsonObject);
348330
}
349331

350-
this.verbose(
351-
`Received message from ${ ch } channel`,
352-
`, data: ${ JSON.stringify(message) }`,
332+
this.verbose(`Received message from ${
333+
ch } channel, data: ${
334+
JSON.stringify(message) }`,
353335
);
354336
});
355337

@@ -366,7 +348,7 @@ export class RedisQueue extends EventEmitter<EventMap>
366348
this.verbose('Initialize unsubscribing...');
367349

368350
if (this.subscriptionName) {
369-
await this.subscription.unsubscribe(
351+
this.subscription.unsubscribe(
370352
`${this.options.prefix}:${this.subscriptionName}`,
371353
);
372354

@@ -376,7 +358,7 @@ export class RedisQueue extends EventEmitter<EventMap>
376358

377359
this.subscription.removeAllListeners();
378360
this.subscription.disconnect(false);
379-
await this.subscription.quit();
361+
this.subscription.quit();
380362
}
381363

382364
this.subscriptionName = undefined;
@@ -407,10 +389,10 @@ export class RedisQueue extends EventEmitter<EventMap>
407389
jsonData,
408390
);
409391

410-
this.verbose(
411-
`Published message to ${ name } channel`,
412-
`, data: ${ jsonData }`,
413-
);
392+
this.verbose(`Published message to ${
393+
name } channel, data: ${
394+
jsonData }
395+
`);
414396
}
415397

416398
/**
@@ -516,9 +498,6 @@ export class RedisQueue extends EventEmitter<EventMap>
516498
const data: IMessage = { id, message, from: this.name };
517499
const key = `${this.options.prefix}:${toQueue}`;
518500
const packet = this.pack(data);
519-
520-
this.verbose('Message send', `: ${ packet }`, true);
521-
522501
const cb = (error: any, op: string) => {
523502
// istanbul ignore next
524503
if (error) {
@@ -531,14 +510,11 @@ export class RedisQueue extends EventEmitter<EventMap>
531510
};
532511

533512
if (delay) {
534-
await this.writer.zadd(
535-
`${key}:delayed`,
536-
Date.now() + delay,
537-
packet,
538-
(e: Error | null) => {
513+
this.writer.zadd(`${key}:delayed`, Date.now() + delay, packet,
514+
(err: any) => {
539515
// istanbul ignore next
540-
if (e) {
541-
cb(e, 'ZADD');
516+
if (err) {
517+
cb(err, 'ZADD');
542518

543519
return;
544520
}
@@ -553,10 +529,9 @@ export class RedisQueue extends EventEmitter<EventMap>
553529
}
554530
},
555531
).catch((err: any) => cb(err, 'SET'));
556-
},
557-
);
532+
});
558533
} else {
559-
await this.writer.lpush(key, packet, (err: any) => {
534+
this.writer.lpush(key, packet, (err: any) => {
560535
// istanbul ignore next
561536
if (err) {
562537
cb(err, 'LPUSH');
@@ -581,7 +556,7 @@ export class RedisQueue extends EventEmitter<EventMap>
581556
if (this.reader) {
582557
this.verbose('Destroying reader...');
583558
this.reader.removeAllListeners();
584-
await this.reader.quit();
559+
this.reader.quit();
585560
this.reader.disconnect(false);
586561

587562
delete this.reader;
@@ -807,10 +782,10 @@ export class RedisQueue extends EventEmitter<EventMap>
807782

808783
// istanbul ignore next
809784
if (context[channel]) {
810-
return context[channel] as IRedisClient;
785+
return context[channel];
811786
}
812787

813-
return new Promise<IRedisClient>((resolve, reject) => {
788+
return new Promise((resolve, reject) => {
814789
const redis = new Redis({
815790
// istanbul ignore next
816791
port: options.port || 6379,
@@ -833,7 +808,7 @@ export class RedisQueue extends EventEmitter<EventMap>
833808
});
834809

835810
context[channel] = makeRedisSafe(redis);
836-
(context[channel] as IRedisClient).__imq = true;
811+
context[channel].__imq = true;
837812

838813
for (const event of [
839814
'wait',
@@ -1016,10 +991,8 @@ export class RedisQueue extends EventEmitter<EventMap>
1016991
try {
1017992
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument
1018993
const { id, message, from } = this.unpack(data);
1019-
1020994
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1021995
this.emit('message', message, id, from);
1022-
this.verbose('Message received', `: ${ data }`, true);
1023996
} catch (err) {
1024997
// istanbul ignore next
1025998
this.emitError(
@@ -1162,7 +1135,7 @@ export class RedisQueue extends EventEmitter<EventMap>
11621135
*/
11631136
private async onWatchMessage(...args: any[]): Promise<void> {
11641137
try {
1165-
const key = ((args.pop() || '') + '').split(':');
1138+
const key = (args.pop() || '').split(':');
11661139

11671140
if (key.pop() !== 'ttl') {
11681141
return;

0 commit comments

Comments
 (0)