@jetit/publisher 4.0.0 → 4.1.0
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/lib/redis/streams.d.ts +20 -9
- package/src/lib/redis/streams.js +15 -8
- package/src/lib/redis/utils.d.ts +7 -0
- package/src/lib/redis/utils.js +16 -1
package/package.json
CHANGED
|
@@ -121,14 +121,25 @@ export declare class Streams {
|
|
|
121
121
|
*/
|
|
122
122
|
close(): Promise<void>;
|
|
123
123
|
private cleanupAcknowledgedMessages;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
getDiagnosticData(events: string[]): Promise<{
|
|
125
|
+
status: string;
|
|
126
|
+
message: string;
|
|
127
|
+
data?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
status: string;
|
|
130
|
+
data: {
|
|
131
|
+
eventName: string;
|
|
132
|
+
consumerGroupMap: {
|
|
133
|
+
consumerGroup: string;
|
|
134
|
+
diagnostics: Generator<Promise<unknown[]> | {
|
|
135
|
+
count: number;
|
|
136
|
+
consumers: {
|
|
137
|
+
consumerName: string;
|
|
138
|
+
pendingCount: string;
|
|
139
|
+
}[];
|
|
140
|
+
}, void, [number, string, string, string[][]]>;
|
|
141
|
+
}[];
|
|
142
|
+
}[];
|
|
143
|
+
message: string;
|
|
133
144
|
}>;
|
|
134
145
|
}
|
package/src/lib/redis/streams.js
CHANGED
|
@@ -317,14 +317,21 @@ class Streams {
|
|
|
317
317
|
await this.redisGroups.zremrangebyscore(`ack:${streamName}`, '-inf', cleanupThreshold);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
320
|
+
async getDiagnosticData(events) {
|
|
321
|
+
if (events.length > 100) {
|
|
322
|
+
return { status: 'ERROR', message: 'Please pass in a maximum of 100 elements to fetch diagnostics' };
|
|
323
|
+
}
|
|
324
|
+
const tempPromises = events.map(async (eventName) => {
|
|
325
|
+
const consumerGroups = await (0, utils_1.getAllConsumerGroups)(eventName, this.redisPublisher);
|
|
326
|
+
const consumerGroupMap = await Promise.all(consumerGroups.map(async (consumerGroup) => {
|
|
327
|
+
const streamName = `${eventName}:${consumerGroup}`;
|
|
328
|
+
const diagnostics = await (0, utils_1.getSummaryOnStreamConsumerGroup)(this.redisGroups, consumerGroup, streamName);
|
|
329
|
+
return { consumerGroup, diagnostics };
|
|
330
|
+
}));
|
|
331
|
+
return { eventName, consumerGroupMap };
|
|
332
|
+
});
|
|
333
|
+
const returnData = await await Promise.all(tempPromises);
|
|
334
|
+
return { status: 'SUCCESS', data: returnData, message: 'We recommend not running this in times of heavy load' };
|
|
328
335
|
}
|
|
329
336
|
}
|
|
330
337
|
exports.Streams = Streams;
|
package/src/lib/redis/utils.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { RedisType } from './registry';
|
|
2
2
|
import { EventData } from './types';
|
|
3
3
|
export declare function getAllConsumerGroups(eventName: string, redisConnection: RedisType): Promise<string[]>;
|
|
4
|
+
export declare function getSummaryOnStreamConsumerGroup(redisClient: RedisType, consumerGroupName: string, streamName: string): Generator<Promise<unknown[]> | {
|
|
5
|
+
count: number;
|
|
6
|
+
consumers: {
|
|
7
|
+
consumerName: string;
|
|
8
|
+
pendingCount: string;
|
|
9
|
+
}[];
|
|
10
|
+
}, void, [number, string, string, string[][]]>;
|
|
4
11
|
export declare function getUnacknowledgedMessages(redisClient: RedisType, consumerGroupName: string, streamName: string, consumerName: string, count?: number): Promise<{
|
|
5
12
|
count: number;
|
|
6
13
|
countOnThisConsumer?: number;
|
package/src/lib/redis/utils.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UTILS = exports.decodeScheduledMessage = exports.encodeScheduledMessage = exports.removedScheduledJob = exports.notifySubscribers = exports.getMessageStatesCount = exports.getUnacknowledgedMessages = exports.getAllConsumerGroups = void 0;
|
|
3
|
+
exports.UTILS = exports.decodeScheduledMessage = exports.encodeScheduledMessage = exports.removedScheduledJob = exports.notifySubscribers = exports.getMessageStatesCount = exports.getUnacknowledgedMessages = exports.getSummaryOnStreamConsumerGroup = exports.getAllConsumerGroups = void 0;
|
|
4
4
|
const logger_1 = require("./logger");
|
|
5
5
|
async function getAllConsumerGroups(eventName, redisConnection) {
|
|
6
6
|
const consumerGroups = await redisConnection.smembers(`${eventName}`);
|
|
7
7
|
return consumerGroups;
|
|
8
8
|
}
|
|
9
9
|
exports.getAllConsumerGroups = getAllConsumerGroups;
|
|
10
|
+
function* getSummaryOnStreamConsumerGroup(redisClient, consumerGroupName, streamName) {
|
|
11
|
+
const [count, , , consumers] = (yield redisClient.xpending(streamName, consumerGroupName));
|
|
12
|
+
yield {
|
|
13
|
+
count,
|
|
14
|
+
consumers: consumers
|
|
15
|
+
? consumers.map((x) => {
|
|
16
|
+
return {
|
|
17
|
+
consumerName: x[0],
|
|
18
|
+
pendingCount: x[1],
|
|
19
|
+
};
|
|
20
|
+
})
|
|
21
|
+
: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.getSummaryOnStreamConsumerGroup = getSummaryOnStreamConsumerGroup;
|
|
10
25
|
async function getUnacknowledgedMessages(redisClient, consumerGroupName, streamName, consumerName, count = 500) {
|
|
11
26
|
try {
|
|
12
27
|
// Get pending messages summary
|