Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support partial batch responses on all handlers #75

Merged
merged 1 commit into from
May 24, 2024

Conversation

swain
Copy link
Contributor

@swain swain commented May 24, 2024

Motivation

Currently, we only support partial batch responses for our SQS handler. But, all of the event sources we support (Kinesis, Dynamo, SQS) actually support using partial batch responses.

The medical results team would like to use Kinesis partial batch responses. So, this PR adds support for partial batch responses in all of our handlers.

I went ahead and used a breaking change just for sanity.

@lifeomic-probot
Copy link

lifeomic-probot bot commented May 24, 2024

⚠️ Detected a breaking change in commit 6a9ccce

Merging this PR will result in a major version bump.

Created by lifeomic-probot (Enforce Semantic Commits)

@swain swain force-pushed the partial-batch-responses branch from 6c9a325 to 6a9ccce Compare May 24, 2024 19:32
@swain swain marked this pull request as ready for review May 24, 2024 19:34
{
items: event.Records,
// If there is not a MessageGroupId, then we don't care about
// the ordering for the event. We can just generate a UUID for the
// ordering key.
orderBy: (record) => record.attributes.MessageGroupId ?? uuid(),
orderBy: (record: SQSRecord) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm - I guess now that we're reusing this for all sources the record can't really be generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is total cruft. The type here is inferred from event.Records. The explicit type is not needed.

Comment on lines -379 to -384
subsequentUnprocessedRecords: [
expect.objectContaining({
body: JSON.stringify({
name: `test-event-4`,
}),
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost verifying that the subsequent unprocessed records are also reported, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aecorredor Unfortunately, it's slightly worse. We don't actually report subsequentUnprocessedRecords at all.

Thanks for catching it.

Would you mind if I follow-up with re-adding that improvement? Getting this fix out for the medical-results team is actually time-sensitive -- would love to have it before the weekend.

Comment on lines -398 to -404
subsequentUnprocessedRecords: [
expect.objectContaining({
body: JSON.stringify({
name: `test-event-8`,
}),
}),
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Or am I missing something? I do see that you still track subsequent unprocessed records, so we could validate that in the test, right?

);

return { batchItemFailures };
return handleUnprocessedRecords({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think the new approach is simpler - but I felt like it'd be nice for this methods to not have to be another import, since we always want to call it after calling processWithOrdering right? Either to decide if we should throw or if we should accept partial batching.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing something out there, maybe the return type of processWithOrdering makes is just a method that is called to do what handleUnprocessedRecords is doing. That way things are more direct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aecorredor I had the same feeling. I think that could be a nice follow-up improvement.

@aecorredor
Copy link
Member

Super nice! I liked that not a whole lot of changes were needed to make this work. Your new abstraction is also simpler 🚀

Copy link

@aymanenadi aymanenadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@swain swain requested a review from aecorredor May 24, 2024 20:07
@swain swain merged commit 96737df into master May 24, 2024
4 checks passed
@swain swain deleted the partial-batch-responses branch May 24, 2024 20:12
Copy link

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants