updating consumer

This commit is contained in:
Emily
2025-01-31 15:33:26 +01:00
parent 487c3ac7b4
commit 881a7800ce
7 changed files with 426 additions and 20 deletions

View File

@@ -11,6 +11,9 @@ importers:
'@types/node':
specifier: ^22.10.10
version: 22.10.10
'@types/redis':
specifier: ^4.0.11
version: 4.0.11
date-fns:
specifier: ^4.1.0
version: 4.1.0
@@ -61,6 +64,10 @@ packages:
'@types/node@22.10.10':
resolution: {integrity: sha512-X47y/mPNzxviAGY5TcYPtYL8JsY3kAq2n8fMmKoRCxq/c4v4pyGNCzM2R6+M5/umG4ZfHuT+sgqDYqWc9rJ6ww==}
'@types/redis@4.0.11':
resolution: {integrity: sha512-bI+gth8La8Wg/QCR1+V1fhrL9+LZUSWfcqpOj2Kc80ZQ4ffbdL173vQd5wovmoV9i071FU9oP2g6etLuEwb6Rg==}
deprecated: This is a stub types definition. redis provides its own type definitions, so you do not need this installed.
'@types/webidl-conversions@7.0.3':
resolution: {integrity: sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==}
@@ -213,6 +220,10 @@ snapshots:
dependencies:
undici-types: 6.20.0
'@types/redis@4.0.11':
dependencies:
redis: 4.7.0
'@types/webidl-conversions@7.0.3': {}
'@types/whatwg-url@11.0.5':

View File

@@ -29,9 +29,20 @@ export class RedisStreamService {
await this.client.connect();
}
static async getQueueInfo(stream_name: string) {
try {
const size = await this.client.xLen(stream_name);
return size;
} catch (ex) {
console.error(ex);
return 0;
}
}
static async readFromStream(stream_name: string, group_name: string, consumer_name: string, process_function: (content: Record<string, string>) => Promise<any>) {
const result: xReadGgroupResult = await this.client.xReadGroup(group_name, consumer_name, [{ key: stream_name, id: '>' }], { COUNT: 5, BLOCK: 10000 });
const result: xReadGgroupResult = await this.client.xReadGroup(group_name, consumer_name, [{ key: stream_name, id: '>' }], { COUNT: 5, BLOCK: 2000 });
if (!result) {
setTimeout(() => this.readFromStream(stream_name, group_name, consumer_name, process_function), 10);