@@ -10,6 +10,7 @@ import {
10
10
import { BrowserToolService } from 'src/modules/browser/services/browser-tool/browser-tool.service' ;
11
11
import ERROR_MESSAGES from 'src/constants/error-messages' ;
12
12
import {
13
+ AckPendingEntriesDto , AckPendingEntriesResponse ,
13
14
ConsumerDto ,
14
15
GetConsumersDto , GetPendingEntriesDto , PendingEntryDto ,
15
16
} from 'src/modules/browser/dto/stream.dto' ;
@@ -61,16 +62,16 @@ export class ConsumerService {
61
62
}
62
63
63
64
/**
64
- * Get list of pending messages info for particular consumer
65
+ * Get list of pending entries info for particular consumer
65
66
* @param clientOptions
66
67
* @param dto
67
68
*/
68
- async getPendingMessages (
69
+ async getPendingEntries (
69
70
clientOptions : IFindRedisClientInstanceByOptions ,
70
71
dto : GetPendingEntriesDto ,
71
72
) : Promise < PendingEntryDto [ ] > {
72
73
try {
73
- this . logger . log ( 'Getting pending messages list.' ) ;
74
+ this . logger . log ( 'Getting pending entries list.' ) ;
74
75
75
76
const exists = await this . browserTool . execCommand (
76
77
clientOptions ,
@@ -82,7 +83,7 @@ export class ConsumerService {
82
83
return Promise . reject ( new NotFoundException ( ERROR_MESSAGES . KEY_NOT_EXIST ) ) ;
83
84
}
84
85
85
- return ConsumerService . formatReplyToPendingMessagesDto ( await this . browserTool . execCommand (
86
+ return ConsumerService . formatReplyToPendingEntriesDto ( await this . browserTool . execCommand (
86
87
clientOptions ,
87
88
BrowserToolStreamCommands . XPending ,
88
89
[ dto . keyName , dto . groupName , dto . start , dto . end , dto . count , dto . consumerName ] ,
@@ -100,6 +101,52 @@ export class ConsumerService {
100
101
}
101
102
}
102
103
104
+ /**
105
+ * Get list of pending entries info for particular consumer
106
+ * @param clientOptions
107
+ * @param dto
108
+ */
109
+ async ackPendingEntries (
110
+ clientOptions : IFindRedisClientInstanceByOptions ,
111
+ dto : AckPendingEntriesDto ,
112
+ ) : Promise < AckPendingEntriesResponse > {
113
+ try {
114
+ this . logger . log ( 'Acknowledging pending entries.' ) ;
115
+
116
+ const exists = await this . browserTool . execCommand (
117
+ clientOptions ,
118
+ BrowserToolKeysCommands . Exists ,
119
+ [ dto . keyName ] ,
120
+ ) ;
121
+
122
+ if ( ! exists ) {
123
+ return Promise . reject ( new NotFoundException ( ERROR_MESSAGES . KEY_NOT_EXIST ) ) ;
124
+ }
125
+
126
+ const affected = await this . browserTool . execCommand (
127
+ clientOptions ,
128
+ BrowserToolStreamCommands . XAck ,
129
+ [ dto . keyName , dto . groupName , ...dto . entries ] ,
130
+ ) ;
131
+
132
+ this . logger . log ( 'Successfully acknowledged pending entries.' ) ;
133
+
134
+ return {
135
+ affected,
136
+ } ;
137
+ } catch ( error ) {
138
+ if ( error instanceof NotFoundException ) {
139
+ throw error ;
140
+ }
141
+
142
+ if ( error ?. message . includes ( RedisErrorCodes . WrongType ) ) {
143
+ throw new BadRequestException ( error . message ) ;
144
+ }
145
+
146
+ throw catchAclError ( error ) ;
147
+ }
148
+ }
149
+
103
150
/**
104
151
* Converts RESP response from Redis
105
152
* [
@@ -167,15 +214,15 @@ export class ConsumerService {
167
214
* ]
168
215
* @param reply
169
216
*/
170
- static formatReplyToPendingMessagesDto ( reply : Array < Array < string | number > > ) : PendingEntryDto [ ] {
171
- return reply . map ( ConsumerService . formatArrayToPendingMessageDto ) ;
217
+ static formatReplyToPendingEntriesDto ( reply : Array < Array < string | number > > ) : PendingEntryDto [ ] {
218
+ return reply . map ( ConsumerService . formatArrayToPendingEntryDto ) ;
172
219
}
173
220
174
221
/**
175
222
* Format single reply entry to DTO
176
223
* @param entry
177
224
*/
178
- static formatArrayToPendingMessageDto ( entry : Array < string | number > ) : PendingEntryDto {
225
+ static formatArrayToPendingEntryDto ( entry : Array < string | number > ) : PendingEntryDto {
179
226
if ( ! entry ?. length ) {
180
227
return null ;
181
228
}
0 commit comments