Abstract class for batch processors.

This class provides a common interface for processing records in a batch.

Batch processors implementing this class should provide implementations for a number of abstract methods that are specific to the type of processor or the type of records being processed.

The class comes with a few helper methods and hooks that can be used to prepare the processor before processing records, clean up after processing records, and handle records that succeed or fail processing.

Hierarchy (view full)

Constructors

Properties

errors: Error[]

List of errors that occurred during processing

failureMessages: EventSourceDataClassTypes[]

List of records that failed processing

handler: CallableFunction

Record handler provided by customers to process records

Options to be used during processing (optional)

records: BaseRecord[]

List of records to be processed

successMessages: EventSourceDataClassTypes[]

List of records that were processed successfully

Methods

  • Clean or resets the processor instance after completing a batch

    This method should be called after processing a full batch to reset the processor.

    You can use this as a hook to run any cleanup logic after processing the records.

    Returns void

  • Prepare class instance before processing

    This method should be called before processing the records

    You can use this as a hook to run any setup logic before processing the records.

    Returns void

  • Process all records with an asynchronous handler

    Once called, the processor will create an array of promises to process each record and wait for all of them to settle before returning the results.

    Before and after processing, the processor will call the prepare and clean methods respectively.

    Returns Promise<(SuccessResponse | FailureResponse)[]>

  • Process a record with an asynchronous handler

    An implementation of this method is required for asynchronous processors.

    When implementing this method, you should at least call the successHandler method when a record succeeds processing and the failureHandler method when a record fails processing.

    This is to ensure that the processor keeps track of the results and the records that succeeded and failed processing.

    Parameters

    Returns Promise<SuccessResponse | FailureResponse>

  • Process a record with a synchronous handler

    An implementation of this method is required for synchronous processors.

    When implementing this method, you should at least call the successHandler method when a record succeeds processing and the failureHandler method when a record fails processing.

    This is to ensure that the processor keeps track of the results and the records that succeeded and failed processing.

    Parameters

    Returns SuccessResponse | FailureResponse

  • Orchestrate the processing of a batch of records synchronously and sequentially.

    The method is responsible for calling the prepare method before processing the records and the clean method after processing the records.

    In the middle, the method will iterate over the records and call the processRecordSync method for each record.

    Returns (SuccessResponse | FailureResponse)[]

    List of processed records

  • Set up the processor with the records and the handler

    This method should be called before processing the records to bind the records and the handler for a specific invocation to the processor.

    We use a separate method to do this rather than the constructor to allow for reusing the processor instance across multiple invocations by instantiating the processor outside of the Lambda function handler.

    Parameters

    • records: BaseRecord[]

      Array of records to be processed

    • handler: CallableFunction

      CallableFunction to process each record from the batch

    • Optionaloptions: BatchProcessingOptions

      Options to be used during processing (optional)

    Returns this

  • Method to handle a record that succeeded processing

    This method should be called when a record succeeds processing so that the processor can keep track of the result and the record that succeeded.

    Parameters

    Returns SuccessResponse