redis-consumer 1.1.7 → 1.1.9
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/dist/consumer.js +29 -21
- package/package.json +2 -2
package/dist/consumer.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedisConsumer = void 0;
|
|
4
4
|
const retry_processor_1 = require("./retry-processor");
|
|
5
|
+
let errs = "error";
|
|
5
6
|
class RedisConsumer {
|
|
6
7
|
client;
|
|
7
8
|
originalClient;
|
|
@@ -36,7 +37,7 @@ class RedisConsumer {
|
|
|
36
37
|
get settings() {
|
|
37
38
|
return { block: this.BLOCK, count: this.COUNT };
|
|
38
39
|
}
|
|
39
|
-
async listen(streams) {
|
|
40
|
+
async listen(streams, flag) {
|
|
40
41
|
if (!Array.isArray(streams)) {
|
|
41
42
|
streams = [streams];
|
|
42
43
|
}
|
|
@@ -48,7 +49,7 @@ class RedisConsumer {
|
|
|
48
49
|
if (this.hasStreamState(stream.name)) continue;
|
|
49
50
|
this.initStreamState(stream);
|
|
50
51
|
}
|
|
51
|
-
this.listenForStreams();
|
|
52
|
+
this.listenForStreams(flag);
|
|
52
53
|
}
|
|
53
54
|
addAckMessage(stream, id) {
|
|
54
55
|
if (this.successfullMessages.has(stream)) {
|
|
@@ -58,7 +59,7 @@ class RedisConsumer {
|
|
|
58
59
|
this.successfullMessages.set(stream, [id]);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
async listenForStreams() {
|
|
62
|
+
async listenForStreams(flag) {
|
|
62
63
|
const state = this.state;
|
|
63
64
|
const streamsToListen = [];
|
|
64
65
|
for (const stream in state) {
|
|
@@ -67,13 +68,13 @@ class RedisConsumer {
|
|
|
67
68
|
const streamsMessages = await this.readStreams(streamsToListen);
|
|
68
69
|
if (!streamsMessages) {
|
|
69
70
|
await this.acknowlegdeMessages();
|
|
70
|
-
this.listenForStreams();
|
|
71
|
+
this.listenForStreams(flag);
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
for (const streamMessages of streamsMessages) {
|
|
74
|
-
await this.processStreamMessages(streamMessages);
|
|
75
|
+
await this.processStreamMessages(streamMessages, flag);
|
|
75
76
|
}
|
|
76
|
-
this.listenForStreams();
|
|
77
|
+
this.listenForStreams(flag);
|
|
77
78
|
}
|
|
78
79
|
hasStreamState(name) {
|
|
79
80
|
return !!this.getStreamState(name);
|
|
@@ -102,28 +103,35 @@ class RedisConsumer {
|
|
|
102
103
|
);
|
|
103
104
|
return messages;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
|
|
107
|
+
async handle(fnc, message, stream) {
|
|
108
|
+
try {
|
|
109
|
+
await fnc(message, stream);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if (errs == "error") errs = err;
|
|
112
|
+
this.client.emit("process-error", err, { stream, message, retries: 0 });
|
|
113
|
+
if (this.RETRIES === 0) return;
|
|
114
|
+
if (err instanceof Error) {
|
|
115
|
+
this.retryProcessor.add(err, stream, message, fnc);
|
|
116
|
+
} else {
|
|
117
|
+
const newErr = new Error(String(err));
|
|
118
|
+
this.retryProcessor.add(newErr, stream, message, fnc);
|
|
119
|
+
}
|
|
120
|
+
} finally {
|
|
121
|
+
if (errs && errs != "error") (console.error(errs), (errs = ""));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async processStreamMessages(streamMessages, flag) {
|
|
106
125
|
const stream = streamMessages.name;
|
|
107
126
|
const state = this.getStreamState(stream);
|
|
108
127
|
if (!state)
|
|
109
128
|
throw new Error("No state was found for stream processing of " + stream);
|
|
110
129
|
const fnc = state.executable;
|
|
111
130
|
const messages = streamMessages.messages;
|
|
131
|
+
if (flag) await handle(fnc, messages, stream);
|
|
112
132
|
for (const message of messages) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.addAckMessage(stream, message.id);
|
|
116
|
-
} catch (err) {
|
|
117
|
-
// console.error(err);
|
|
118
|
-
this.client.emit("process-error", err, { stream, message, retries: 0 });
|
|
119
|
-
if (this.RETRIES === 0) continue;
|
|
120
|
-
if (err instanceof Error) {
|
|
121
|
-
this.retryProcessor.add(err, stream, message, fnc);
|
|
122
|
-
} else {
|
|
123
|
-
const newErr = new Error(String(err));
|
|
124
|
-
this.retryProcessor.add(newErr, stream, message, fnc);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
133
|
+
if (!flag) await handle(fnc, message, stream);
|
|
134
|
+
this.addAckMessage(stream, message.id);
|
|
127
135
|
}
|
|
128
136
|
await this.acknowlegdeMessages();
|
|
129
137
|
const recovering = state.recovering;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redis-consumer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Simple NodeJs consumer and producer for Redis Streams",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/tomasky/redis-streams-nodejs#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"redis": "^
|
|
36
|
+
"redis": "^4.7.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.15.0",
|