Skip to content

Add batch_size to identify fields in Drip (Actions) #2932

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

Merged
merged 6 commits into from
May 28, 2025

Conversation

jacobpmeyer
Copy link
Contributor

@jacobpmeyer jacobpmeyer commented May 21, 2025

Adding batch_size to the identify fields

Testing

  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [If destination is already live] Tested for backward compatibility of destination. Note: New required fields are a breaking change.
  • [Segmenters] Tested in the staging environment
  • [Segmenters] [If applicable for this change] Tested for regression with Hadron.

@jacobpmeyer jacobpmeyer marked this pull request as ready for review May 21, 2025 23:12
@jacobpmeyer jacobpmeyer requested a review from a team as a code owner May 21, 2025 23:12
Comment on lines 128 to 144
const batchSize = payload[0]?.batch_size ?? 1000
const multiStatusResponse = new MultiStatusResponse()
for (let i = 0; i < payload.length; i += batchSize) {
const chunk = payload.slice(i, i + batchSize)
const subs = chunk.map(person)
const response = await request(`https://api.getdrip.com/v2/${settings.accountId}/subscribers/batches`, {
method: 'POST',
json: { batches: [{ subscribers: subs }] }
})
chunk.forEach((_, index) => {
multiStatusResponse.pushSuccessResponse({
status: response.status,
sent: subs[index],
body: response.data as JSONLikeObject
})
})
}
Copy link
Contributor

@joe-ayoub-segment joe-ayoub-segment May 22, 2025

Choose a reason for hiding this comment

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

hi @jacobpmeyer
Segment's pipeline will ensure that the size of the payload array is already chunked to batch_size. There's no need for you to do this in code.

Also, it seems that you are not inspecting the response values from your requests. Shouldn't your responses tell you if each item in the batch request was good or not?

Finally, if any items are not successful, you should update the multiStatusResponse to indicate which items in the batch failed (for example by using setErrorResponseAtIndex)

Take a look at the multistatus docs here: https://github.com/segmentio/action-destinations/blob/main/docs/multistatus.md

Also there are a few implementations in the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jacobpmeyer - perhaps we move multistatus out of this PR to a follow-up, and evaluate its merit? I don't think our usage of multistatus will be super natural because we do less validation on batches, and I'd prefer that it didn't block this PR in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @joe-ayoub-segment Thanks for the info regarding segment's handling of the chunking. That definitely simplifies implementation.

I'd originally assumed that batch_size would be handled under the hood, but I wasn't seeing multiple requests in the return for my curl during local testing so I though maybe I needed to handle the logic for the extra requests.

In any case, I went ahead and removed the MultiStatusResponse code based on @stevedrip's comment and after looking over the doc again I'm not sure we would've gotten much value out of it anyway with the current Drip API. So it's essentially just a light cleanup of the code that was already there.

Let me know if what's there now looks okay.

Copy link
Contributor

@joe-ayoub-segment joe-ayoub-segment left a comment

Choose a reason for hiding this comment

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

Hi @jacobpmeyer thanks for the PR.
I left a few comments for you to look at.
Kind regards,
Joe

@jacobpmeyer
Copy link
Contributor Author

Hi @joe-ayoub-segment. Thank you so much for the quick and thorough feedback. I made edits to the code where you mentioned. Let me or @stevedrip know if there's anything else that you'd like to see from this PR. I'm going to be out of office tomorrow, so additional changes might come from Steve.

@joe-ayoub-segment joe-ayoub-segment merged commit fca0829 into segmentio:main May 28, 2025
10 of 12 checks passed
@joe-ayoub-segment
Copy link
Contributor

Hi @jacobpmeyer PR deployed. Please confirm that you are happy with the change.

@stevedrip stevedrip deleted the jm/add-batch-size branch May 28, 2025 17:58
@jacobpmeyer
Copy link
Contributor Author

Hi @jacobpmeyer PR deployed. Please confirm that you are happy with the change.

Hey @joe-ayoub-segment. Would I need to wait until next week to remove unsafe_hidden: true, from the batch_size field? It seems that people would actually like to see it in the UI and I'm hoping I can get it done soon.

@joe-ayoub-segment
Copy link
Contributor

hi @jacobpmeyer yes - Tuesday is the next deploy.

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

Successfully merging this pull request may close these issues.

3 participants