-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add idempotency support to post #130
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gorup - To handle the same patterns in stripe-rs
we use the Headers
struct and Client::with_headers
method:
- https://github.com/wyyerd/stripe-rs/blob/master/src/params.rs#L16
- https://github.com/wyyerd/stripe-rs/blob/master/src/client/async.rs#L73
And also sometimes a single named setter:
Can you update the PR to use the Headers
struct instead? (and perhaps either a with_idempotency_key
and/or set_idempotency_key
method...)
Got it, so the method takes in the Headers struct, add the idem key to this headers struct. Will do soon(TM) |
So looking into this, one thing that I see being a problem is that this field needs to be unique per request. To use the If we wanted to have a Looking at the Personally, the best option going forward must have new functions added which allow you to pass fields/arguments per-request, that don't require mutating the Client struct in any way. There are two ways I see that happening. The first is with a new struct like the one in my PR as of now. I see how its not ideal that now there are fn create_sub_idem(request: CreateSubscription, client: Arc<StripeClient>) -> Result<Subscription, &'static str> {
let mut h = client.copy_existing_headers();
h.idempotency_key = Some(Uuid::new_v4().to_string());
let mut attempts_left = 3;
while attempts_left >= 0 {
attempts_left -= 1;
match client.post_form_with_headers(request, &h).await {
Ok(r) => return Ok(r);
Err(e) => error!("Got an error from stripe while creating a sub numleft {} {:?} {:?}", attempts_left, request, e),
}
tokio::time::delay_for(DEFAULT_RETRY_DELAY).await;
}
Err("ran out of attempts")
} let me know your thoughts! Thanks |
Hey!
I need idempotency support [1], and I hacked this together. I manually tested the
post_form_options
and the idempotency works. Unsure of what you all think about placingOptions
where it is, naming, doc-comments, etc. Also, this should/could be added to the other functions likepost
,delete
,delete_query
, etc.It appears that Stripe clients use the model of having another method that just allows for options to be passed in, e.g. javadoc. I think this model works, especially given that it is backwards compatible.
Thanks!
[1] https://stripe.com/docs/api/idempotent_requests