cutoff 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 630a704243a3bd8c2196e0be8bba735eb8f2afb185c3db7ba68f3c8bed242041
4
- data.tar.gz: 1922fbb0c382c62fd894cd8d2f0bfa2d21ef5bbf2cdb5f7b128d9de582c14344
3
+ metadata.gz: 5ac27ce016591276e55afa82f64c08de370a969cb6552cc0d5ae69093d3a9e0c
4
+ data.tar.gz: 31e989979ae04de967a22e8d2457d6da654862603f380dd7521e415c9220148b
5
5
  SHA512:
6
- metadata.gz: 7dcb206df1a3dc2ce265e0b78f0d93a8c3ddfe1f92b52945ff06cc87fa20ecfcaf2f4f9636555966b7c5cd9b624a498be788bd8fdf3d6c67cd9c5ffbd35aa393
7
- data.tar.gz: 8178c8dd01267bc67b96eef6b2ff103f90a9e47954c55d10b33f1c21a39f36701bfb2bfd0e6896f6975a210e66c09611cd8cf419d9ea62b2cf489603dcff8808
6
+ metadata.gz: 4241c63fc4c647c44860aa0781e2966a5eadc1d7edea259851018308d1877d664c46a8d90bd5553f725d2e1fa5f767995b0f27327482bf2ce5128701908aa684
7
+ data.tar.gz: 64d599559055f6d8b3c384b88b5268b02317784bd44fd6be2384fd3c56b1f9da5a9cfb435c4af05c083ba20af6d8865f0c73a8fc46afff261ad70d43fc9c35e4
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.1] - 2021-10-02
11
+
12
+ - Fix Net::HTTP patch to override timeouts given to start
13
+
10
14
  ## [0.4.0] - 2021-10-01
11
15
 
12
16
  - Add benchmarks and slight performance improvements
@@ -29,7 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
33
  - Cutoff class
30
34
  - Mysql2 patch
31
35
 
32
- [Unreleased]: https://github.com/justinhoward/cutoff/compare/v0.4.0...HEAD
36
+ [Unreleased]: https://github.com/justinhoward/cutoff/compare/v0.4.1...HEAD
37
+ [0.4.0]: https://github.com/justinhoward/cutoff/compare/v0.4.0...v0.4.1
33
38
  [0.4.0]: https://github.com/justinhoward/cutoff/compare/v0.3.0...v0.4.0
34
39
  [0.3.0]: https://github.com/justinhoward/cutoff/compare/v0.2.0...v0.3.0
35
40
  [0.2.0]: https://github.com/justinhoward/cutoff/compare/v0.1.0...v0.2.0
@@ -4,27 +4,36 @@ require 'net/http'
4
4
 
5
5
  class Cutoff
6
6
  module Patch
7
- # Adds a checkpoint for starting HTTP requests and sets network timeouts
8
- # to the remaining time
9
7
  module NetHttp
10
- # Construct a {Net::HTTP}, but with the timeouts set to the remaining
11
- # cutoff time if one is active
12
- def initialize(address, port = nil)
13
- super
14
- return unless (cutoff = Cutoff.current)
8
+ def self.gen_timeout_method(name)
9
+ <<~RUBY
10
+ if #{name}.nil? || #{name} > remaining
11
+ self.#{name} = cutoff.seconds_remaining
12
+ end
13
+ RUBY
14
+ end
15
15
 
16
- @open_timeout = cutoff.seconds_remaining
17
- @read_timeout = cutoff.seconds_remaining
18
- @write_timeout = cutoff.seconds_remaining
16
+ def self.use_write_timeout?
17
+ Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.6')
19
18
  end
20
19
 
21
- # Same as the original start, but with a cutoff checkpoint
20
+ # Same as the original start, but adds a checkpoint for starting HTTP
21
+ # requests and sets network timeouts to the remaining time
22
22
  #
23
- # @see {Net::HTTP#start}
24
- def start
25
- Cutoff.checkpoint!
26
- super
27
- end
23
+ # @see Net::HTTP#start
24
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
25
+ def start
26
+ if (cutoff = Cutoff.current)
27
+ remaining = cutoff.seconds_remaining
28
+ #{gen_timeout_method('open_timeout')}
29
+ #{gen_timeout_method('read_timeout')}
30
+ #{gen_timeout_method('write_timeout') if use_write_timeout?}
31
+ #{gen_timeout_method('continue_timeout')}
32
+ Cutoff.checkpoint!
33
+ end
34
+ super
35
+ end
36
+ RUBY
28
37
  end
29
38
  end
30
39
  end
@@ -3,6 +3,6 @@
3
3
  class Cutoff
4
4
  # @return [Gem::Version] The current version of the cutoff gem
5
5
  def self.version
6
- Gem::Version.new('0.4.0')
6
+ Gem::Version.new('0.4.1')
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cutoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Howard
@@ -111,7 +111,7 @@ licenses:
111
111
  - MIT
112
112
  metadata:
113
113
  changelog_uri: https://github.com/justinhoward/cutoff/blob/master/CHANGELOG.md
114
- documentation_uri: https://www.rubydoc.info/gems/cutoff/0.4.0
114
+ documentation_uri: https://www.rubydoc.info/gems/cutoff/0.4.1
115
115
  post_install_message:
116
116
  rdoc_options: []
117
117
  require_paths: