@koala42/redis-highway 0.2.1 → 0.2.3

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.
@@ -110,8 +110,10 @@ class BaseWorker {
110
110
  const messagesStreamIds = messages.map((message) => message.streamMessageId);
111
111
  pipeline.xack(this._streamName, this._groupName, ...messagesStreamIds);
112
112
  const messagesToDLQ = [];
113
+ let retryCountIncr = 0;
113
114
  for (const message of messages) {
114
115
  if (message.retryCount < this._maxRetries) {
116
+ retryCountIncr++;
115
117
  const newJobId = (0, uuid_1.v7)();
116
118
  pipeline.xadd(this._streamName, '*', 'id', newJobId, 'target', this._groupName, 'retryCount', message.retryCount + 1, 'data', message.serializedData);
117
119
  const newStatusKey = this._keys.getJobStatusKey(newJobId);
@@ -123,11 +125,15 @@ class BaseWorker {
123
125
  console.error(`[${this._groupName}] Job ${message.messageUuid} run out of retries. Moving to DLQ`);
124
126
  messagesToDLQ.push(message);
125
127
  // Add message to DLQ stream
126
- pipeline.xadd(this._keys.getDlqStreamKey(), '*', 'id', message.messageUuid, 'group', this._groupName, 'error', errorMessage, 'payload', message.serializedData, 'failedAt', Date.now());
128
+ pipeline.xadd(this._keys.getDlqStreamKey(), '*', 'id', message.messageUuid, 'group', this._groupName, 'error', errorMessage, 'payload', message.serializedData, 'failedAt', timestamp);
127
129
  const statusKey = this._keys.getJobStatusKey(message.messageUuid);
128
130
  pipeline.eval(lua_1.LUA_FINALIZE, 2, statusKey, this._streamName, this._groupName, timestamp, message.streamMessageId);
129
131
  }
130
132
  }
133
+ if (retryCountIncr) {
134
+ const retryCountKey = this._keys.getRetriesKey(this._groupName, timestamp);
135
+ pipeline.incrby(retryCountKey, retryCountIncr);
136
+ }
131
137
  await pipeline.exec();
132
138
  }
133
139
  /**
@@ -13,9 +13,13 @@ export declare class KeyManager {
13
13
  */
14
14
  getDlqStreamKey(): string;
15
15
  /**
16
- * Metrics Hash for storing throughput
16
+ * Metrics for storing throughput
17
17
  */
18
18
  getThroughputKey(groupName: string, timestamp: number): string;
19
+ /**
20
+ * Metrics - retries key
21
+ */
22
+ getRetriesKey(groupName: string, timestamp: number): string;
19
23
  /**
20
24
  * Total jobs processed metrics
21
25
  */
package/dist/src/keys.js CHANGED
@@ -23,12 +23,19 @@ class KeyManager {
23
23
  return `${this.streamName}:dlq`;
24
24
  }
25
25
  /**
26
- * Metrics Hash for storing throughput
26
+ * Metrics for storing throughput
27
27
  */
28
28
  getThroughputKey(groupName, timestamp) {
29
29
  const minute = Math.floor(timestamp / 60000) * 60000;
30
30
  return `metrics:throughput:${this.streamName}:${groupName}:${minute}`;
31
31
  }
32
+ /**
33
+ * Metrics - retries key
34
+ */
35
+ getRetriesKey(groupName, timestamp) {
36
+ const minute = Math.floor(timestamp / 60000) * 60000;
37
+ return `metrics:retry-count:${this.streamName}:${groupName}:${minute}`;
38
+ }
32
39
  /**
33
40
  * Total jobs processed metrics
34
41
  */
@@ -57,6 +57,7 @@ class Metrics {
57
57
  groupNames.forEach(group => {
58
58
  pipeline.get(this.keys.getThroughputKey(group, timestamp));
59
59
  pipeline.get(this.keys.getTotalKey(group));
60
+ pipeline.get(this.keys.getRetriesKey(group, timestamp));
60
61
  });
61
62
  const results = await pipeline.exec();
62
63
  if (!results)
@@ -72,10 +73,11 @@ class Metrics {
72
73
  const response = [];
73
74
  response.push(`# HELP ${prefix}_waiting_jobs Total jobs waiting in stream`, `# TYPE ${prefix}_waiting_jobs gauge`, `${prefix}_waiting_jobs{stream="${this.streamName}"} ${streamLength}`, `# HELP ${prefix}_dlq_jobs Total jobs in DLQ`, `# TYPE ${prefix}_dlq_jobs gauge`, `${prefix}_dlq_jobs{stream="${this.streamName}"} ${dlqLength}`);
74
75
  groupNames.forEach((group, index) => {
75
- const baseIndex = 2 + (index * 2);
76
+ const baseIndex = 2 + (index * 3);
76
77
  const throughputVal = parseInt(getResult(baseIndex) || '0', 10);
77
78
  const totalVal = parseInt(getResult(baseIndex + 1) || '0', 10);
78
- response.push(`# HELP ${prefix}_throughput_1m Jobs processed in the last minute`, `# TYPE ${prefix}_throughput_1m gauge`, `${prefix}_throughput_1m{stream="${this.streamName}", group="${group}"} ${throughputVal}`, `# HELP ${prefix}_jobs_total Total jobs processed`, `# TYPE ${prefix}_jobs_total counter`, `${prefix}_jobs_total{stream="${this.streamName}", group="${group}"} ${totalVal}`);
79
+ const retryCountVal = parseInt(getResult(baseIndex + 2) || '0', 10);
80
+ response.push(`# HELP ${prefix}_throughput_1m Jobs processed in the last minute`, `# TYPE ${prefix}_throughput_1m gauge`, `${prefix}_throughput_1m{stream="${this.streamName}", group="${group}"} ${throughputVal}`, `# HELP ${prefix}_retries_1m Retries in the last minute`, `# TYPE ${prefix}_retries_1m gauge`, `${prefix}_retries_1m{stream="${this.streamName}", group="${group}"} ${retryCountVal}`, `# HELP ${prefix}_jobs_total Total jobs processed`, `# TYPE ${prefix}_jobs_total counter`, `${prefix}_jobs_total{stream="${this.streamName}", group="${group}"} ${totalVal}`);
79
81
  });
80
82
  return response.join('\n');
81
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koala42/redis-highway",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "High performance redis queue",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -16,8 +16,7 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "clean": "rimraf dist",
19
- "test": "vitest run src/queue.spec.ts",
20
- "test:all": "vitest run src",
19
+ "test:all": "vitest run test/queue.spec.ts test/batch-worker.spec.ts",
21
20
  "build": "npm run clean && tsc",
22
21
  "prepublish": "npm run build"
23
22
  },
@@ -28,7 +27,7 @@
28
27
  "high-throughput"
29
28
  ],
30
29
  "dependencies": {
31
- "ioredis": "^5.8.2",
30
+ "ioredis": "5.8.2",
32
31
  "uuid": "^13.0.0"
33
32
  },
34
33
  "devDependencies": {