Skip to content

batch write ignoring failed writes #29

Open
@ktwbc

Description

@ktwbc

The response back from DocumentClient on BatchWrite will include any failed writes, which usually need to be resubmitted (sometimes with a linear backoff)

The call from DynamoDb returns UnprocessedItems but batch_write.js will not check this, and this results in missed items when writing batches to the table.

will try and submit a PR when I have time but I have code from a different attempt which was working but would need to be redone to fit in with how this file works

async.forEachOf(arrParams, function (params: DynamoDB.DocumentClient.BatchWriteItemInput, key: number, eachDone: Callback) {

      let backoffCount = 1;

      let processItemsCallback = (error: AWSError, result: DynamoDB.DocumentClient.BatchWriteItemRequestMap) => {
        
        if (error) {
          return eachDone(error);
        } else {
          if (Object.keys(result.UnprocessedItems).length !== 0) {

            let params: any = {};
            params.RequestItems = result.UnprocessedItems;

            backoffCount++;

            setTimeout(() => {
              dynamoDb.batchWrite(params, processItemsCallback);
            }, 1000 * backoffCount);

          } else {
            eachDone();
          }
        }
      };

      dynamoDb.batchWrite(params, processItemsCallback);

    }, function done(err: Error) {
    ...etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions