11import type { SQSRecord } from 'aws-lambda' ;
22import { BatchProcessorSync } from './BatchProcessorSync.js' ;
3+ import { SqsFifoProcessor } from './SqsFifoProcessor.js' ;
34import { EventType } from './constants.js' ;
45import {
56 type BatchProcessingError ,
@@ -46,17 +47,13 @@ import type {
4647 */
4748class SqsFifoPartialProcessor extends BatchProcessorSync {
4849 /**
49- * The ID of the current message group being processed.
50+ * Processor for handling SQS FIFO message
5051 */
51- #currentGroupId?: string ;
52- /**
53- * A set of group IDs that have already encountered failures.
54- */
55- #failedGroupIds: Set < string > ;
52+ readonly #processor: SqsFifoProcessor ;
5653
5754 public constructor ( ) {
5855 super ( EventType . SQS ) ;
59- this . #failedGroupIds = new Set < string > ( ) ;
56+ this . #processor = new SqsFifoProcessor ( ) ;
6057 }
6158
6259 /**
@@ -70,9 +67,7 @@ class SqsFifoPartialProcessor extends BatchProcessorSync {
7067 record : EventSourceDataClassTypes ,
7168 exception : Error
7269 ) : FailureResponse {
73- if ( this . options ?. skipGroupOnError && this . #currentGroupId) {
74- this . #addToFailedGroup( this . #currentGroupId) ;
75- }
70+ this . #processor. processFailureForCurrentGroup ( this . options ) ;
7671
7772 return super . failureHandler ( record , exception ) ;
7873 }
@@ -101,24 +96,17 @@ class SqsFifoPartialProcessor extends BatchProcessorSync {
10196 const processedRecords : ( SuccessResponse | FailureResponse ) [ ] = [ ] ;
10297 let currentIndex = 0 ;
10398 for ( const record of this . records ) {
104- this . #setCurrentGroup( ( record as SQSRecord ) . attributes ?. MessageGroupId ) ;
99+ this . #processor. setCurrentGroup (
100+ ( record as SQSRecord ) . attributes ?. MessageGroupId
101+ ) ;
105102
106- // If we have any failed messages, we should then short circuit the process and
107- // fail remaining messages unless `skipGroupOnError` is true
108- const shouldShortCircuit =
109- ! this . options ?. skipGroupOnError && this . failureMessages . length !== 0 ;
110- if ( shouldShortCircuit ) {
103+ if (
104+ this . #processor. shouldShortCircuit ( this . failureMessages , this . options )
105+ ) {
111106 return this . shortCircuitProcessing ( currentIndex , processedRecords ) ;
112107 }
113108
114- // If `skipGroupOnError` is true and the current group has previously failed,
115- // then we should skip processing the current group.
116- const shouldSkipCurrentGroup =
117- this . options ?. skipGroupOnError &&
118- this . #currentGroupId &&
119- this . #failedGroupIds. has ( this . #currentGroupId) ;
120-
121- const result = shouldSkipCurrentGroup
109+ const result = this . #processor. shouldSkipCurrentGroup ( this . options )
122110 ? this . #processFailRecord(
123111 record ,
124112 new SqsFifoMessageGroupShortCircuitError ( )
@@ -161,15 +149,6 @@ class SqsFifoPartialProcessor extends BatchProcessorSync {
161149 return processedRecords ;
162150 }
163151
164- /**
165- * Adds the specified group ID to the set of failed group IDs.
166- *
167- * @param group - The group ID to be added to the set of failed group IDs.
168- */
169- #addToFailedGroup( group : string ) : void {
170- this . #failedGroupIds. add ( group ) ;
171- }
172-
173152 /**
174153 * Processes a fail record.
175154 *
@@ -184,15 +163,6 @@ class SqsFifoPartialProcessor extends BatchProcessorSync {
184163
185164 return this . failureHandler ( data , exception ) ;
186165 }
187-
188- /**
189- * Sets the current group ID for the message being processed.
190- *
191- * @param group - The group ID of the current message being processed.
192- */
193- #setCurrentGroup( group ?: string ) : void {
194- this . #currentGroupId = group ;
195- }
196166}
197167
198168export { SqsFifoPartialProcessor } ;
0 commit comments