Skip to content

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
@jylamont jylamont force-pushed the feature/rest_client_timeout branch 2 times, most recently from de874c0 to f27cb15 Compare February 21, 2025 22:47
@jylamont jylamont force-pushed the feature/rest_client_timeout branch from f27cb15 to 3cc33b1 Compare February 24, 2025 15:17
@jylamont jylamont force-pushed the feature/rest_client_timeout branch from 3cc33b1 to 9a98116 Compare February 24, 2025 15:23
@jylamont jylamont merged commit fba6ce0 into master Feb 24, 2025
8 checks passed
@jylamont jylamont deleted the feature/rest_client_timeout branch February 24, 2025 15:23
Comment on lines +33 to +39
def setup_logging!(logger)
RestClient.log = Object.new.tap do |proxy|
def proxy.<<(message)
logger.info message
end
end
end
Copy link

Choose a reason for hiding this comment

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

The proxy object's << method is defined with def, which creates a new scope and loses access to the logger variable. To properly capture the logger, use define_singleton_method instead:

RestClient.log = Object.new.tap do |proxy|
  proxy.define_singleton_method(:<<) { |message| logger.info message }
end

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

jylamont added a commit that referenced this pull request Feb 25, 2025
#70 introduced a bug that would cause requests to fail because of a misconfigured logger, regardless of whether the gem enabled logging.
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

2 participants