async-aws 0.3.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +35 -35
- data/README.md +7 -0
- data/async-aws.gemspec +2 -2
- data/lib/async/aws.rb +10 -12
- data/lib/async/aws/http_handler.rb +18 -35
- data/lib/async/aws/version.rb +1 -1
- metadata +6 -7
- data/lib/async/aws/http_client.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 101257bc534ed74edf2e3dce144db4f7689dcf2b626d693177605438cbe5853b
|
4
|
+
data.tar.gz: 2346df96c07eac2723f486ef9c624dca7fa9970603f2bbc562a81e11251772da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae8bf53175273340c63d4fbf3470d04d07606ac0fa8788d829841cd9047a393266ac3cb6196276bb88aaaf5c632ba73fdd73c27658353f36b45dc62ce4b9ee2
|
7
|
+
data.tar.gz: 7b45cb4941d72f0506b1f179b17535192422eff2c2ce21dec0a86051c8aea2af1112dfb2860e67e72a21bd0ef66c0a11ab2cee4e2da5ba3ad6f08019b6ee60b0
|
data/Gemfile.lock
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
async-aws (0.
|
5
|
-
async-http (~> 0.
|
4
|
+
async-aws (1.0.1)
|
5
|
+
async-http (~> 0.51)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
async (1.
|
10
|
+
async (1.24.2)
|
11
11
|
console (~> 1.0)
|
12
12
|
nio4r (~> 2.3)
|
13
13
|
timers (~> 4.1)
|
14
|
-
async-http (0.
|
14
|
+
async-http (0.51.2)
|
15
15
|
async (~> 1.23)
|
16
|
-
async-io (~> 1.
|
16
|
+
async-io (~> 1.28)
|
17
17
|
async-pool (~> 0.2)
|
18
|
-
protocol-http (~> 0.
|
19
|
-
protocol-http1 (~> 0.
|
20
|
-
protocol-http2 (~> 0.
|
21
|
-
async-io (1.
|
18
|
+
protocol-http (~> 0.18.0)
|
19
|
+
protocol-http1 (~> 0.12.0)
|
20
|
+
protocol-http2 (~> 0.13.0)
|
21
|
+
async-io (1.28.0)
|
22
22
|
async (~> 1.14)
|
23
23
|
async-pool (0.2.0)
|
24
24
|
async (~> 1.8)
|
25
|
-
aws-eventstream (1.0
|
26
|
-
aws-partitions (1.
|
27
|
-
aws-sdk-core (3.
|
28
|
-
aws-eventstream (~> 1
|
29
|
-
aws-partitions (~> 1.0)
|
25
|
+
aws-eventstream (1.1.0)
|
26
|
+
aws-partitions (1.296.0)
|
27
|
+
aws-sdk-core (3.94.0)
|
28
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
29
|
+
aws-partitions (~> 1, >= 1.239.0)
|
30
30
|
aws-sigv4 (~> 1.1)
|
31
31
|
jmespath (~> 1.0)
|
32
|
-
aws-sdk-dynamodb (1.
|
33
|
-
aws-sdk-core (~> 3, >= 3.
|
32
|
+
aws-sdk-dynamodb (1.45.0)
|
33
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
34
34
|
aws-sigv4 (~> 1.1)
|
35
|
-
aws-sdk-kms (1.
|
36
|
-
aws-sdk-core (~> 3, >= 3.
|
35
|
+
aws-sdk-kms (1.30.0)
|
36
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
37
37
|
aws-sigv4 (~> 1.1)
|
38
|
-
aws-sdk-s3 (1.
|
39
|
-
aws-sdk-core (~> 3, >= 3.
|
38
|
+
aws-sdk-s3 (1.61.2)
|
39
|
+
aws-sdk-core (~> 3, >= 3.83.0)
|
40
40
|
aws-sdk-kms (~> 1)
|
41
41
|
aws-sigv4 (~> 1.1)
|
42
|
-
aws-sigv4 (1.1.
|
42
|
+
aws-sigv4 (1.1.1)
|
43
43
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
44
|
-
console (1.
|
44
|
+
console (1.8.2)
|
45
45
|
diff-lcs (1.3)
|
46
46
|
jmespath (1.4.0)
|
47
47
|
nio4r (2.5.2)
|
48
|
-
protocol-hpack (1.4.
|
49
|
-
protocol-http (0.
|
50
|
-
protocol-http1 (0.
|
51
|
-
protocol-http (~> 0.
|
52
|
-
protocol-http2 (0.
|
48
|
+
protocol-hpack (1.4.2)
|
49
|
+
protocol-http (0.18.0)
|
50
|
+
protocol-http1 (0.12.0)
|
51
|
+
protocol-http (~> 0.18)
|
52
|
+
protocol-http2 (0.13.3)
|
53
53
|
protocol-hpack (~> 1.4)
|
54
|
-
protocol-http (~> 0.
|
55
|
-
rake (
|
54
|
+
protocol-http (~> 0.18)
|
55
|
+
rake (13.0.1)
|
56
56
|
rspec (3.9.0)
|
57
57
|
rspec-core (~> 3.9.0)
|
58
58
|
rspec-expectations (~> 3.9.0)
|
59
59
|
rspec-mocks (~> 3.9.0)
|
60
|
-
rspec-core (3.9.
|
61
|
-
rspec-support (~> 3.9.
|
62
|
-
rspec-expectations (3.9.
|
60
|
+
rspec-core (3.9.1)
|
61
|
+
rspec-support (~> 3.9.1)
|
62
|
+
rspec-expectations (3.9.1)
|
63
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
64
|
rspec-support (~> 3.9.0)
|
65
|
-
rspec-mocks (3.9.
|
65
|
+
rspec-mocks (3.9.1)
|
66
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
67
|
rspec-support (~> 3.9.0)
|
68
|
-
rspec-support (3.9.
|
68
|
+
rspec-support (3.9.2)
|
69
69
|
timers (4.3.0)
|
70
70
|
|
71
71
|
PLATFORMS
|
@@ -77,7 +77,7 @@ DEPENDENCIES
|
|
77
77
|
aws-sdk-dynamodb
|
78
78
|
aws-sdk-s3
|
79
79
|
bundler (~> 2.0)
|
80
|
-
rake (~>
|
80
|
+
rake (~> 13.0)
|
81
81
|
rspec (~> 3.0)
|
82
82
|
|
83
83
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -20,6 +20,13 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install async-aws
|
22
22
|
|
23
|
+
## Configuration
|
24
|
+
```ruby
|
25
|
+
Async::Aws.configure(
|
26
|
+
connection_limit: 4 # Max number of connections per endpoint (passed to Async::HTTP::Client)
|
27
|
+
)
|
28
|
+
```
|
29
|
+
|
23
30
|
## Usage
|
24
31
|
|
25
32
|
### Method 1
|
data/async-aws.gemspec
CHANGED
@@ -28,10 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency 'async-http', '~> 0.
|
31
|
+
spec.add_dependency 'async-http', '~> 0.51'
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
-
spec.add_development_dependency "rake", "~>
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
36
|
spec.add_development_dependency "aws-sdk-s3"
|
37
37
|
spec.add_development_dependency "aws-sdk-dynamodb"
|
data/lib/async/aws.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'async/http'
|
2
|
-
require 'async/http/internet'
|
3
|
-
require 'async/aws/http_client'
|
4
2
|
require 'async/aws/http_handler'
|
5
3
|
require 'async/aws/http_plugin'
|
6
4
|
|
@@ -8,24 +6,24 @@ module Async
|
|
8
6
|
module Aws
|
9
7
|
module_function
|
10
8
|
|
11
|
-
def
|
12
|
-
@
|
9
|
+
def config
|
10
|
+
@config ||= {}
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
|
13
|
+
def configure(**kwargs)
|
14
|
+
config.merge!(kwargs.slice(:connection_limit))
|
17
15
|
end
|
18
16
|
|
19
|
-
def
|
20
|
-
|
17
|
+
def set(key, value)
|
18
|
+
__send__("#{key}=".to_sym, value)
|
21
19
|
end
|
22
20
|
|
23
|
-
def
|
24
|
-
|
21
|
+
def connection_limit=(arg)
|
22
|
+
config[:connection_limit] = arg.to_i
|
25
23
|
end
|
26
24
|
|
27
|
-
def
|
28
|
-
|
25
|
+
def connection_limit
|
26
|
+
config.fetch(:connection_limit, 1)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -5,47 +5,38 @@ module Async
|
|
5
5
|
@clients ||= {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.
|
9
|
-
|
10
|
-
klass.connection_pool_size = kwargs.fetch(
|
11
|
-
:connection_pool_size, Async::Aws.connection_pool_size
|
12
|
-
)
|
13
|
-
klass.keep_alive_timeout = kwargs.fetch(
|
14
|
-
:keep_alive_timeout, Async::Aws.keep_alive_timeout
|
15
|
-
)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.connection_pool_size
|
20
|
-
@connection_pool_size ||= Async::Aws.connection_pool_size
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.connection_pool_size=(value)
|
24
|
-
@connection_pool_size = value.to_i
|
8
|
+
def self.endpoints
|
9
|
+
@endpoints ||= {}
|
25
10
|
end
|
26
11
|
|
27
|
-
def self.
|
28
|
-
|
12
|
+
def self.endpoint_for(url)
|
13
|
+
endpoints[url.to_s] ||= Async::HTTP::Endpoint.parse(url.to_s)
|
29
14
|
end
|
30
15
|
|
31
|
-
def self.
|
32
|
-
|
16
|
+
def self.client_for(endpoint)
|
17
|
+
clients[endpoint.hostname] ||= ::Async::HTTP::Client.new(
|
18
|
+
endpoint,
|
19
|
+
retries: 0,
|
20
|
+
connection_limit: Async::Aws.connection_limit
|
21
|
+
)
|
33
22
|
end
|
34
23
|
|
35
24
|
def call(context)
|
36
25
|
req = context.http_request
|
37
26
|
resp = context.http_response
|
38
|
-
endpoint =
|
27
|
+
endpoint = self.class.endpoint_for(req.endpoint)
|
39
28
|
|
40
29
|
begin
|
41
|
-
client = client_for(endpoint)
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
client = self.class.client_for(endpoint)
|
31
|
+
headers = ::Protocol::HTTP::Headers.new(
|
32
|
+
req.headers.reject do |k, v|
|
33
|
+
k == 'host' || k == 'content-length'
|
34
|
+
end
|
35
|
+
)
|
45
36
|
buffered_body = Async::HTTP::Body::Buffered.wrap(req.body)
|
46
37
|
request = ::Protocol::HTTP::Request.new(
|
47
38
|
client.scheme, endpoint.authority, req.http_method, endpoint.path,
|
48
|
-
nil,
|
39
|
+
nil, headers, buffered_body
|
49
40
|
)
|
50
41
|
response = client.call(request)
|
51
42
|
body = response.read
|
@@ -59,14 +50,6 @@ module Async
|
|
59
50
|
|
60
51
|
Seahorse::Client::Response.new(context: context)
|
61
52
|
end
|
62
|
-
|
63
|
-
def client_for(endpoint)
|
64
|
-
self.class.clients[endpoint.hostname] ||= ::Async::Aws::HttpClient.new(
|
65
|
-
endpoint,
|
66
|
-
pool_size: self.class.connection_pool_size,
|
67
|
-
keep_alive_timeout: self.class.keep_alive_timeout
|
68
|
-
)
|
69
|
-
end
|
70
53
|
end
|
71
54
|
end
|
72
55
|
end
|
data/lib/async/aws/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien D.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.51'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.51'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,6 @@ files:
|
|
130
130
|
- lib/async-aws.rb
|
131
131
|
- lib/async/aws.rb
|
132
132
|
- lib/async/aws/all.rb
|
133
|
-
- lib/async/aws/http_client.rb
|
134
133
|
- lib/async/aws/http_handler.rb
|
135
134
|
- lib/async/aws/http_plugin.rb
|
136
135
|
- lib/async/aws/version.rb
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'async/io/endpoint'
|
4
|
-
require 'async/io/stream'
|
5
|
-
require 'protocol/http/body/streamable'
|
6
|
-
require 'protocol/http/methods'
|
7
|
-
|
8
|
-
module Async
|
9
|
-
module Aws
|
10
|
-
class HttpClient < ::Protocol::HTTP::Methods
|
11
|
-
attr_accessor :keep_alive_timeout
|
12
|
-
attr_reader :scheme
|
13
|
-
|
14
|
-
ConnectionSpec = Struct.new(:connection, :used_at)
|
15
|
-
|
16
|
-
# Provides a robust interface to a server.
|
17
|
-
# * If there are no connections, it will create one.
|
18
|
-
# * If there are already connections, it will reuse it.
|
19
|
-
# * If a request fails, it will retry it up to N times if it was idempotent.
|
20
|
-
# The client object will never become unusable. It internally manages persistent connections (or non-persistent connections if that's required).
|
21
|
-
# @param endpoint [Endpoint] the endpoint to connnect to.
|
22
|
-
# @param protocol [Protocol::HTTP1 | Protocol::HTTP2 | Protocol::HTTPS] the protocol to use.
|
23
|
-
# @param scheme [String] The default scheme to set to requests.
|
24
|
-
# @param authority [String] The default authority to set to requests.
|
25
|
-
def initialize(endpoint, pool_size: 2, keep_alive_timeout: 5)
|
26
|
-
@endpoint = endpoint
|
27
|
-
@protocol = endpoint.protocol
|
28
|
-
@scheme = endpoint.scheme
|
29
|
-
@authority = endpoint.authority
|
30
|
-
@keep_alive_timeout = keep_alive_timeout
|
31
|
-
@clock_gettime_constant = \
|
32
|
-
if defined?(Process::CLOCK_MONOTONIC)
|
33
|
-
Process::CLOCK_MONOTONIC
|
34
|
-
else
|
35
|
-
Process::CLOCK_REALTIME
|
36
|
-
end
|
37
|
-
@pool = make_pool(pool_size)
|
38
|
-
end
|
39
|
-
|
40
|
-
def close
|
41
|
-
until @pool.empty?
|
42
|
-
connection_spec = @pool.dequeue
|
43
|
-
connection_spec.connection.close
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def call(request)
|
48
|
-
request.scheme ||= self.scheme
|
49
|
-
request.authority ||= self.authority
|
50
|
-
|
51
|
-
attempt = 0
|
52
|
-
|
53
|
-
# We may retry the request if it is possible to do so. https://tools.ietf.org/html/draft-nottingham-httpbis-retry-01 is a good guide for how retrying requests should work.
|
54
|
-
begin
|
55
|
-
attempt += 1
|
56
|
-
|
57
|
-
# As we cache pool, it's possible these pool go bad (e.g. closed by remote host). In this case, we need to try again. It's up to the caller to impose a timeout on this. If this is the last attempt, we force a new connection.
|
58
|
-
connection_spec = @pool.dequeue
|
59
|
-
if connection_spec.used_at + keep_alive_timeout <= current_time
|
60
|
-
connection_spec.connection.close
|
61
|
-
connection_spec = create_connection_spec
|
62
|
-
end
|
63
|
-
|
64
|
-
# send request
|
65
|
-
response = request.call(connection_spec.connection)
|
66
|
-
|
67
|
-
# The connection won't be released until the body is completely read/released.
|
68
|
-
::Protocol::HTTP::Body::Streamable.wrap(response) do
|
69
|
-
connection_spec.used_at = current_time
|
70
|
-
@pool << connection_spec
|
71
|
-
end
|
72
|
-
|
73
|
-
return response
|
74
|
-
rescue => e
|
75
|
-
@pool << connection_spec if connection_spec
|
76
|
-
raise e
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def current_time
|
83
|
-
Process.clock_gettime(@clock_gettime_constant)
|
84
|
-
end
|
85
|
-
|
86
|
-
def create_connection_spec
|
87
|
-
ConnectionSpec.new(
|
88
|
-
@protocol.client(@endpoint.connect),
|
89
|
-
current_time
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
def make_pool(size)
|
94
|
-
Async::Queue.new.tap do |queue|
|
95
|
-
size.times do
|
96
|
-
queue << create_connection_spec
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|