-
Notifications
You must be signed in to change notification settings - Fork 137
Make network timeouts configurable #412
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
Conversation
|
Hey @sidonath - thanks for your contribution! To be totally honest, I'm not quite sure what problem you're handling with the code in this PR. From what I understand our API doesn't allow any configurable timeouts, so this isn't something that can be changed through this client either. Your specs don't seem to handle any change in behavior - just that the settings you've adjusted have been properly set as well. I'm going to close this PR for now, but in the chance that I'm wrong(entirely possible) - please feel to re-open. |
|
Hi @theandrewykim 👋
The problem is that However, because of the way timeouts for Net::HTTP are set, we're not able to change them from our application: This PR simply attempts to provide the public API to configure the timeouts.
Right, I never thought the timeout can be set through the Intercom API, it's a network-related technicality 😊
That's all the PR attempts to do, yes 😄 I'd really appreciate if you'd reconsider merging the PR, because otherwise we'd be forced to use the fork and keep it up to date. If you see any downsides of making the network timeouts configurable in this way, please let me know and maybe we can come up with a different solution! As I'm not a contributor, I'm afraid I can't reopen this PR 😞 |
|
Hi @sidonath, thanks for explaining why you need this functionality. I agree that the network timeouts should be configurable, so I'll reopen this pull request for you. On the implementation - what do you think of passing the timeouts to intercom-ruby/lib/intercom/client.rb Line 113 in f3448ff
That way they don't have to be threaded through |
Timeout configuration is a client concern, but currently the configuration is buried deep in internals of the library. So, as a first step, we can move the configuration of the Request to the `#execute` method. We can leverage kwargs to provide default values for timeouts and make them configurable from outside at the same time. This change doesn't have tests because it would require dangereous mocking and stubbing of objects we don't control.
The Request instances are not exposed to the outside world, so any configuration needs to happen directly from Client. This is a refactoring step in which we move the definition of timeouts from Request to Client.
As a last step, we add the `set_timeouts` class method that returns options for configuring a client with custom timeouts. Both timeouts can be set at once, but it's also possible to configure just one of them if necessary. The `set_timeouts` method uses kwargs to explicitly define its interface, whereas `timeout=` is a private method so it works with hash arguments for convenience.
|
Thank you @eugeneius! That's a great idea and makes the change much smaller. I guess I missed that execution path 😅 I've updated the PR with the new approach. |
jonnyom
left a comment
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.
Hey @sidonath thanks for updating this. I'm happy to approve this for you now 👍
Timeouts to external services should be a concern of a client, as it could affect its reliability and performance.
Unfortunately, in the current architecture, it's not possible to cleanly change timeouts from (very generous, if I may say) defaults.
This PR attempts to make network timeout settings configurable, relying on the existing plumbing for configuring the client.
I couldn't think of a clean way to write a spec that asserts timeouts actually get applied to Net::HTTP, but it's rather easy to see in console: