-
Notifications
You must be signed in to change notification settings - Fork 22
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
Configurable http_timeout
on API requests
#70
base: master
Are you sure you want to change the base?
Conversation
a315a22
to
5724560
Compare
5724560
to
3b7c4ca
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
91166c4
to
a3dd975
Compare
ea3dfee
to
e4579a9
Compare
a3dd975
to
046d486
Compare
e4579a9
to
a3c498e
Compare
046d486
to
8c632a0
Compare
def do_request(method, a_url, params) | ||
raise ArgumentError, ":method must be one of the follow: #{ALLOWED_HTTP_METHODS.join(', ')}" unless ALLOWED_HTTP_METHODS.include?(method) | ||
|
||
rest_client_args = { | ||
method: method, | ||
url: a_url, | ||
timeout: http_timeout | ||
} | ||
|
||
if method == :get | ||
rest_client_args.merge!(headers: { params: params }) | ||
else | ||
rest_client_args.merge!(payload: JSON.dump(params), headers: { content_type: :json, accept: :json }) | ||
end | ||
|
||
def request_content_type | ||
{ content_type: :json, accept: :json } | ||
RestClient::Request.execute( | ||
method: method, | ||
url: a_url, | ||
headers: { params: params }, | ||
timeout: http_timeout | ||
) | ||
end |
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.
The do_request
method builds a rest_client_args
hash with the correct configuration, but then ignores it in favor of a hardcoded RestClient::Request.execute
call. The method should use the prepared arguments by passing them directly:
RestClient::Request.execute(rest_client_args)
This would properly apply all the configured options including the correct headers and payload formatting.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
This PR adds support for setting a timeout for executing API requests. By default, it will use 60 seconds (which is also the default RestClient uses) but this can be changed by setting
config.http_timeout = xxx
to the desired number of seconds. To support this feature, the code calling RestClient had to be fully refactored.Fixes #63