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

Configurable http_timeout on API requests #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jylamont
Copy link
Contributor

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

@jylamont jylamont changed the base branch from release/0.10.0 to master April 17, 2024 22:52
@jylamont jylamont force-pushed the feature/rest_client_timeout branch 2 times, most recently from a315a22 to 5724560 Compare April 17, 2024 23:15
@jylamont jylamont changed the base branch from master to 04-17-improve_added_github_action_ci April 17, 2024 23:18
@jylamont jylamont force-pushed the feature/rest_client_timeout branch from 5724560 to 3b7c4ca Compare April 17, 2024 23:18
@jylamont jylamont force-pushed the feature/rest_client_timeout branch 2 times, most recently from 91166c4 to a3dd975 Compare April 17, 2024 23:49
@jylamont jylamont force-pushed the 04-17-improve_added_github_action_ci branch from ea3dfee to e4579a9 Compare April 18, 2024 00:02
@jylamont jylamont force-pushed the feature/rest_client_timeout branch from a3dd975 to 046d486 Compare April 18, 2024 00:02
@jylamont jylamont force-pushed the 04-17-improve_added_github_action_ci branch from e4579a9 to a3c498e Compare April 18, 2024 00:10
Base automatically changed from 04-17-improve_added_github_action_ci to master April 18, 2024 00:11
@jylamont jylamont force-pushed the feature/rest_client_timeout branch from 046d486 to 8c632a0 Compare April 18, 2024 18:17
Comment on lines +73 to 94
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
Copy link

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.

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

Successfully merging this pull request may close these issues.

Support for http timeout
1 participant