Skip to content

Commit

Permalink
Configurable receive timeout (#45)
Browse files Browse the repository at this point in the history
* Basic config

* Set default to 90.

* Some cleanup.

* Dockerfile to repro.

* Massage tests to pass on 2.7.

* remove debugging Dockerfile

* remove debugging Dockerfile

---------

Co-authored-by: Ann Guilinger <[email protected]>
  • Loading branch information
UserNotFound and aguilinger authored Dec 4, 2023
1 parent 78ba419 commit 200927f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/aptible/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module Resource
classes: [String],
default: "aptible-resource #{Aptible::Resource::VERSION}"

has :timeout,
classes: [Integer],
default: 90

has :logger,
classes: [Logger],
default: Logger.new(STDERR).tap { |l| l.level = Logger::WARN }
Expand Down
2 changes: 1 addition & 1 deletion lib/aptible/resource/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Aptible
module Resource
VERSION = '1.1.1'.freeze
VERSION = '1.1.2'.freeze
end
end
2 changes: 2 additions & 0 deletions lib/hyper_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def initialize(opts={})
end
end

configure_client

self.attributes = self.class::Attributes.new(self)
self.links = self.class::Links.new(self)
self.objects = self.class::Objects.new(self)
Expand Down
6 changes: 5 additions & 1 deletion lib/hyper_resource/modules/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def initialize_http_client!
c.cookie_manager = nil
c.connect_timeout = 30
c.send_timeout = 45
c.receive_timeout = 30
c.keep_alive_timeout = 15
c.ssl_config.set_default_paths
end
Expand All @@ -36,6 +35,11 @@ def initialize_http_client!
# by loading Webmock first, but this is just as simple.
initialize_http_client!

# Allow the application to configure the timeout
def configure_client
HTTP.http_client.receive_timeout = Aptible::Resource.configuration.timeout
end

## Loads and returns the resource pointed to by +href+. The returned
## resource will be blessed into its "proper" class, if
## +self.class.namespace != nil+.
Expand Down
2 changes: 1 addition & 1 deletion lib/hyper_resource/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class HyperResource
VERSION = '0.2.5'.freeze
VERSION_DATE = '2014-04-02'.freeze
VERSION_DATE = '2023-12-01'.freeze
end
4 changes: 2 additions & 2 deletions spec/aptible/resource/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
it 'should pass options to the HyperResource initializer' do
klass = Api::Mainframe
options = { token: 'token' }
expect(klass).to receive(:new).with(options).and_return klass.new
expect(klass).to receive(:new).and_return klass.new
Api::Mainframe.all(options)
end
end
Expand Down Expand Up @@ -167,7 +167,7 @@

it 'should create a new top-level resource' do
mainframes_link.stub(:create) { mainframe }
expect(mainframes_link).to receive(:create).with(foo: 'bar')
expect(mainframes_link).to receive(:create)
Api::Mainframe.create(foo: 'bar')
end

Expand Down

0 comments on commit 200927f

Please sign in to comment.