restify 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/restify.rb +3 -2
- data/lib/restify/adapter/pooled_em.rb +11 -10
- data/lib/restify/adapter/typhoeus.rb +29 -16
- data/lib/restify/global.rb +2 -5
- data/lib/restify/logging.rb +11 -0
- data/lib/restify/request.rb +4 -0
- data/lib/restify/version.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- metadata +16 -2
- data/lib/restify/railtie.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 218f1484655662a863e6d65ae81f8f1cfe5e3127f9c795748b150236fe137225
|
4
|
+
data.tar.gz: 440710396a4f3879ad78766ef074edc85a51c5e40b7b8a3ac685e41b5060abf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d065b2b0b1080d937e311dcc7f820c41fad880262112887d57e5051888a069244809b3dd3e14307ce553277c82b8d56f602f5b891178f3df78b82aa45c13655
|
7
|
+
data.tar.gz: a4fd01db3ece23055dc2b3d4c297f5caf06bb93294cc4e9cd79a72fcca87340014d5f03b90603be32a2dff8006df6fb3a6375056258cae2e669643dca4024ef1
|
data/CHANGELOG.md
CHANGED
data/lib/restify.rb
CHANGED
@@ -12,6 +12,8 @@ require 'addressable/template'
|
|
12
12
|
#
|
13
13
|
module Restify
|
14
14
|
require 'restify/error'
|
15
|
+
require 'restify/logging'
|
16
|
+
|
15
17
|
require 'restify/promise'
|
16
18
|
require 'restify/registry'
|
17
19
|
require 'restify/global'
|
@@ -27,6 +29,7 @@ module Restify
|
|
27
29
|
|
28
30
|
module Adapter
|
29
31
|
require 'restify/adapter/base'
|
32
|
+
require 'restify/adapter/typhoeus'
|
30
33
|
end
|
31
34
|
|
32
35
|
module Processors
|
@@ -34,8 +37,6 @@ module Restify
|
|
34
37
|
require 'restify/processors/json'
|
35
38
|
end
|
36
39
|
|
37
|
-
require 'restify/railtie' if defined?(Rails::Railtie)
|
38
|
-
|
39
40
|
PROCESSORS = [Processors::Json].freeze
|
40
41
|
|
41
42
|
extend Global
|
@@ -6,8 +6,7 @@ require 'em-http-request'
|
|
6
6
|
module Restify
|
7
7
|
module Adapter
|
8
8
|
class PooledEM < Base
|
9
|
-
|
10
|
-
LOG_PROGNAME = 'restify.adapter.pooled-em'.freeze
|
9
|
+
include Logging
|
11
10
|
|
12
11
|
# This class maintains a pool of connection objects, grouped by origin,
|
13
12
|
# and ensures limits for total parallel requests and per-origin requests.
|
@@ -16,6 +15,8 @@ module Restify
|
|
16
15
|
# When any of them are checked out for usage, it counts the usages to
|
17
16
|
# prevent constraints being broken.
|
18
17
|
class Pool
|
18
|
+
include Logging
|
19
|
+
|
19
20
|
def initialize(size: 32, per_host: 6, connect_timeout: 2, inactivity_timeout: 10)
|
20
21
|
@size = size
|
21
22
|
@per_host = per_host
|
@@ -64,7 +65,7 @@ module Restify
|
|
64
65
|
@available.unshift(conn) if @available.size < @size
|
65
66
|
@used -= 1 if @used > 0
|
66
67
|
|
67
|
-
|
68
|
+
logger.debug do
|
68
69
|
"[#{conn.uri}] Released to pool (#{@available.size}/#{@used}/#{size})"
|
69
70
|
end
|
70
71
|
|
@@ -76,7 +77,7 @@ module Restify
|
|
76
77
|
def remove(conn)
|
77
78
|
close(conn)
|
78
79
|
|
79
|
-
|
80
|
+
logger.debug do
|
80
81
|
"[#{conn.uri}] Removed from pool (#{@available.size}/#{@used}/#{size})"
|
81
82
|
end
|
82
83
|
|
@@ -121,7 +122,7 @@ module Restify
|
|
121
122
|
def reuse_connection(index, origin)
|
122
123
|
@used += 1
|
123
124
|
@available.delete_at(index).tap do
|
124
|
-
|
125
|
+
logger.debug do
|
125
126
|
"[#{origin}] Take connection from pool " \
|
126
127
|
"(#{@available.size}/#{@used}/#{size})"
|
127
128
|
end
|
@@ -135,7 +136,7 @@ module Restify
|
|
135
136
|
|
136
137
|
@used += 1
|
137
138
|
new(origin).tap do
|
138
|
-
|
139
|
+
logger.debug do
|
139
140
|
"[#{origin}] Add new connection to pool " \
|
140
141
|
"(#{@available.size}/#{@used}/#{size})"
|
141
142
|
end
|
@@ -145,14 +146,14 @@ module Restify
|
|
145
146
|
def close_oldest
|
146
147
|
close(@available.pop)
|
147
148
|
|
148
|
-
|
149
|
+
logger.debug do
|
149
150
|
"[#{origin}] Closed oldest connection in pool " \
|
150
151
|
"(#{@available.size}/#{@used}/#{size})"
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
154
155
|
def queue(defer)
|
155
|
-
|
156
|
+
logger.debug do
|
156
157
|
"[#{origin}] Wait for free slot " \
|
157
158
|
"(#{@available.size}/#{@used}/#{size})"
|
158
159
|
end
|
@@ -161,7 +162,7 @@ module Restify
|
|
161
162
|
end
|
162
163
|
|
163
164
|
def new(origin)
|
164
|
-
|
165
|
+
logger.debug do
|
165
166
|
"Connect to '#{origin}' " \
|
166
167
|
"(#{@connect_timeout}/#{@inactivity_timeout})..."
|
167
168
|
end
|
@@ -263,7 +264,7 @@ module Restify
|
|
263
264
|
begin
|
264
265
|
EventMachine.run {}
|
265
266
|
rescue => e
|
266
|
-
|
267
|
+
logger.error(e)
|
267
268
|
raise e
|
268
269
|
end
|
269
270
|
end
|
@@ -5,8 +5,7 @@ require 'typhoeus'
|
|
5
5
|
module Restify
|
6
6
|
module Adapter
|
7
7
|
class Typhoeus < Base
|
8
|
-
|
9
|
-
LOG_PROGNAME = 'restify.adapter.typhoeus'.freeze
|
8
|
+
include Logging
|
10
9
|
|
11
10
|
attr_reader :sync
|
12
11
|
|
@@ -27,11 +26,12 @@ module Restify
|
|
27
26
|
|
28
27
|
def call_native(request, writer)
|
29
28
|
@mutex.synchronize do
|
29
|
+
logger.debug { "[#{request.object_id}] Queue request #{request}" }
|
30
30
|
@hydra.queue convert(request, writer)
|
31
31
|
@hydra.dequeue_many
|
32
32
|
end
|
33
33
|
|
34
|
-
sync? ? @hydra.run :
|
34
|
+
sync? ? @hydra.run : thread.run
|
35
35
|
end
|
36
36
|
|
37
37
|
def queued?
|
@@ -53,6 +53,8 @@ module Restify
|
|
53
53
|
connecttimeout: request.timeout
|
54
54
|
|
55
55
|
req.on_complete do |response|
|
56
|
+
logger.debug { "[#{request.object_id}] Completed: #{response.code}" }
|
57
|
+
|
56
58
|
if response.timed_out?
|
57
59
|
writer.reject Restify::Timeout.new request
|
58
60
|
elsif response.code == 0
|
@@ -75,26 +77,37 @@ module Restify
|
|
75
77
|
end
|
76
78
|
|
77
79
|
def convert_headers(headers)
|
78
|
-
headers.
|
80
|
+
return {} unless headers.respond_to?(:each_pair)
|
81
|
+
|
82
|
+
headers.each_pair.each_with_object({}) do |header, memo|
|
79
83
|
memo[header[0].upcase.tr('-', '_')] = header[1]
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
83
|
-
def
|
84
|
-
thread.
|
87
|
+
def thread
|
88
|
+
if @thread.nil? || !@thread.status
|
89
|
+
# Recreate thread if nil or dead
|
90
|
+
@thread = Thread.new { _loop }
|
91
|
+
end
|
92
|
+
|
93
|
+
@thread
|
85
94
|
end
|
86
95
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
96
|
+
def _loop
|
97
|
+
loop { _run }
|
98
|
+
end
|
99
|
+
|
100
|
+
def _run
|
101
|
+
if queued?
|
102
|
+
logger.debug { 'Run hydra' }
|
103
|
+
@hydra.run
|
104
|
+
logger.debug { 'Hydra finished' }
|
105
|
+
else
|
106
|
+
logger.debug { 'Pause hydra thread' }
|
107
|
+
Thread.stop
|
97
108
|
end
|
109
|
+
rescue StandardError => e
|
110
|
+
logger.error(e)
|
98
111
|
end
|
99
112
|
end
|
100
113
|
end
|
data/lib/restify/global.rb
CHANGED
@@ -10,7 +10,6 @@ module Restify
|
|
10
10
|
|
11
11
|
def adapter
|
12
12
|
@adapter ||= begin
|
13
|
-
require 'restify/adapter/typhoeus'
|
14
13
|
Restify::Adapter::Typhoeus.new
|
15
14
|
end
|
16
15
|
end
|
@@ -31,13 +30,11 @@ module Restify
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def logger
|
34
|
-
|
35
|
-
logger.level = :info
|
36
|
-
end
|
33
|
+
::Logging.logger[Restify]
|
37
34
|
end
|
38
35
|
|
39
36
|
def logger=(logger)
|
40
|
-
|
37
|
+
|
41
38
|
end
|
42
39
|
|
43
40
|
private
|
data/lib/restify/request.rb
CHANGED
data/lib/restify/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -41,7 +41,10 @@ RSpec.configure do |config|
|
|
41
41
|
config.order = 'random'
|
42
42
|
|
43
43
|
config.before(:each) do
|
44
|
-
|
44
|
+
Ethon.logger = ::Logging.logger[Ethon] if defined?(Ethon)
|
45
|
+
|
46
|
+
::Logging.logger.root.level = :debug
|
47
|
+
::Logging.logger.root.add_appenders ::Logging.appenders.stdout
|
45
48
|
end
|
46
49
|
|
47
50
|
config.after(:each) do
|
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.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: logging
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,10 +143,10 @@ files:
|
|
129
143
|
- lib/restify/error.rb
|
130
144
|
- lib/restify/global.rb
|
131
145
|
- lib/restify/link.rb
|
146
|
+
- lib/restify/logging.rb
|
132
147
|
- lib/restify/processors/base.rb
|
133
148
|
- lib/restify/processors/json.rb
|
134
149
|
- lib/restify/promise.rb
|
135
|
-
- lib/restify/railtie.rb
|
136
150
|
- lib/restify/registry.rb
|
137
151
|
- lib/restify/relation.rb
|
138
152
|
- lib/restify/request.rb
|