restify 1.3.1 → 1.4.0

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
  SHA1:
3
- metadata.gz: efafa496c201a2b0a9e9c08772dc6975ea76e37b
4
- data.tar.gz: 247851fc3d0492a2ae373b969555f52af44d3845
3
+ metadata.gz: 82d3b62e23db7cb179cce7f4b8a31fe3d965f674
4
+ data.tar.gz: bee7bbacb6e8f25b326af0fba70f12a5609f7aa2
5
5
  SHA512:
6
- metadata.gz: 0f40c4d42f9a08e3fbb068f35f19ef7e26e3b55e06e9f465fa93dcc4671d95f4f1039af1020f443a04481c14866a6001760cb7ef1951149c6ecdd1f181a62684
7
- data.tar.gz: 6ca87fb113af1ae61152157c91a03668829d70792f86726b373c7c5b42c0a25e0f3500b11c11361a5253ca20441c28112ce284e0b232215a4f5e20516141acaf
6
+ metadata.gz: a1385660f21c2f4543a84227d49a821edaa57d515d78ba68102e5a75781d188c181fd3fec32e7444275dd951aabcfebd97174bafa654fc1b53a051bc16990559
7
+ data.tar.gz: 7dba379faf8e84c513ae6adc66a1f8b4ab4fe9f2f546958fe9a561ae14d335c2045d1a4559c23f5f9ea6c4753d9289f3cd21b170a5ad85232f84934068ca0272
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ * Fix possible concurrency issue with typhoeus adapter
6
+ * Add timeout option to requests (only supported by typhoeus adapter)
7
+
3
8
  ## 1.3.1
4
9
 
5
10
  * Improve typhoeus adapters initial request queuing
@@ -5,6 +5,9 @@ require 'typhoeus'
5
5
  module Restify
6
6
  module Adapter
7
7
  class Typhoeus < Base
8
+ # rubocop:disable RedundantFreeze
9
+ LOG_PROGNAME = 'restify.adapter.typhoeus'.freeze
10
+
8
11
  attr_reader :sync
9
12
 
10
13
  DEFAULT_HEADERS = {
@@ -46,10 +49,19 @@ module Restify
46
49
  request.uri,
47
50
  method: request.method,
48
51
  headers: DEFAULT_HEADERS.merge(request.headers),
49
- body: request.body
52
+ body: request.body,
53
+ followlocation: true,
54
+ timeout: request.timeout,
55
+ connecttimeout: request.timeout
50
56
 
51
57
  req.on_complete do |response|
52
- writer.fulfill convert_back(response, request)
58
+ if response.timed_out?
59
+ writer.reject Restify::Timeout.new request
60
+ elsif response.code == 0
61
+ writer.reject Restify::NetworkError.new response.return_message
62
+ else
63
+ writer.fulfill convert_back(response, request)
64
+ end
53
65
  end
54
66
 
55
67
  req
@@ -78,8 +90,8 @@ module Restify
78
90
  @thread ||= Thread.new do
79
91
  loop do
80
92
  begin
81
- Thread.stop unless queued?
82
93
  @hydra.run
94
+ Thread.stop unless queued?
83
95
  rescue StandardError => e
84
96
  puts "#{self.class}: #{e.message}"
85
97
  end
@@ -48,12 +48,13 @@ module Restify
48
48
  end
49
49
 
50
50
  # rubocop:disable Metrics/MethodLength
51
- def request(method, uri, data = nil, _opts = {})
52
- request = Request.new \
51
+ def request(method, uri, data: nil, **kwargs)
52
+ request = Request.new(**kwargs,
53
53
  method: method,
54
54
  uri: join(uri),
55
55
  data: data,
56
56
  headers: headers
57
+ )
57
58
 
58
59
  ret = cache.call(request) {|req| adapter.call(req) }
59
60
  ret.then do |response|
data/lib/restify/error.rb CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  module Restify
4
4
  #
5
+
6
+ # A {Timeout} is raised when a request or promise times out.
7
+ #
8
+ class Timeout < StandardError
9
+ attr_reader :source
10
+
11
+ def initialize(source)
12
+ super "Operation with #{source.class} has timed out"
13
+
14
+ @source = source
15
+ end
16
+ end
17
+
18
+ # A {NetworkError} is raised on unusual network exceptions such as
19
+ # unresolvable hosts or disconnects.
20
+ #
21
+ class NetworkError < StandardError
22
+ end
23
+
5
24
  # A {ResponseError} is returned on a non-successful
6
25
  # response from server. Usually it will either be a
7
26
  # {ClientError} or a {ServerError}.
@@ -20,28 +20,28 @@ module Restify
20
20
  @template = Addressable::Template.new template
21
21
  end
22
22
 
23
- def request(method, data, params)
24
- context.request method, expand(params), data
23
+ def request(method, data, params, opts = {})
24
+ context.request method, expand(params), **opts, data: data
25
25
  end
26
26
 
27
- def get(params = {})
28
- request :get, nil, params
27
+ def get(params = {}, opts = {})
28
+ request :get, nil, params, opts
29
29
  end
30
30
 
31
- def delete(params = {})
32
- request :delete, nil, params
31
+ def delete(params = {}, opts = {})
32
+ request :delete, nil, params, opts
33
33
  end
34
34
 
35
- def post(data = {}, params = {})
36
- request :post, data, params
35
+ def post(data = {}, params = {}, opts = {})
36
+ request :post, data, params, opts
37
37
  end
38
38
 
39
- def put(data = {}, params = {})
40
- request :put, data, params
39
+ def put(data = {}, params = {}, opts = {})
40
+ request :put, data, params, opts
41
41
  end
42
42
 
43
- def patch(data = {}, params = {})
44
- request :patch, data, params
43
+ def patch(data = {}, params = {}, opts = {})
44
+ request :patch, data, params, opts
45
45
  end
46
46
 
47
47
  def ==(other)
@@ -24,10 +24,17 @@ module Restify
24
24
  #
25
25
  attr_reader :headers
26
26
 
27
+ # Request timeout in seconds
28
+ #
29
+ # Defaults to 300 seconds.
30
+ #
31
+ attr_reader :timeout
32
+
27
33
  def initialize(opts = {})
28
34
  @method = opts.fetch(:method, :get).downcase
29
35
  @uri = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' }
30
36
  @data = opts.fetch(:data, nil)
37
+ @timeout = opts.fetch(:timeout, 300)
31
38
  @headers = opts.fetch(:headers, {}).merge \
32
39
  'Content-Type' => 'application/json'
33
40
  end
@@ -3,8 +3,8 @@
3
3
  module Restify
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 3
7
- PATCH = 1
6
+ MINOR = 4
7
+ PATCH = 0
8
8
  STAGE = nil
9
9
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen