em_aws 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49361cc87da75f49666ef20b60d0d82d36355a07
4
+ data.tar.gz: 920d28d847758295a211b65ce4ed0b673d6e8672
5
+ SHA512:
6
+ metadata.gz: f60b1eb1b144e118c1abe09efbd7a79f31a11296886a3b85ab8f0affb401ad5ff503df971504340fd005583aeef844b10a711717c176d394270960435d09a779
7
+ data.tar.gz: 3a39e0d232ae95e67fe6085f9df28de7985b0d651c71d3546f088a3395c94d0b8cfed2ecece1c8425fe6243dedbc79a448b053cddb3796ce6763bf12d92d4a84
data/.rspec CHANGED
@@ -1 +1,3 @@
1
- --color
1
+ --color
2
+ --format documentation
3
+ --profile
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.2.4
7
+ - 2.1.8
8
+ - 2.0.0-p648
9
+ - ruby-head
10
+ - rbx-2
11
+ - jruby-head
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: jruby-head
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'ZenTest', '~> 4.8.2'
7
+ gem 'rake'
8
8
  gem 'eventmachine_httpserver', :require => 'evma_httpserver'
9
9
  end
data/Gemfile.lock CHANGED
@@ -1,56 +1,73 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- em_aws (0.3.2)
5
- aws-sdk (>= 1.9.3)
4
+ em_aws (0.4.0.beta)
5
+ aws-sdk-v1
6
+ em-hot_tub (~> 1.1.0)
6
7
  em-http-request
7
8
  em-synchrony
8
- hot_tub (~> 0.2.4)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- ZenTest (4.8.4)
14
- addressable (2.3.4)
15
- aws-sdk (1.11.3)
13
+ ZenTest (4.11.0)
14
+ addressable (2.4.0)
15
+ autotest (4.4.6)
16
+ ZenTest (>= 4.4.1)
17
+ aws-sdk-v1 (1.66.0)
16
18
  json (~> 1.4)
17
- nokogiri (< 1.6.0)
18
- uuidtools (~> 2.1)
19
- builder (3.2.2)
19
+ nokogiri (>= 1.4.4)
20
20
  cookiejar (0.3.0)
21
- diff-lcs (1.2.4)
22
- em-http-request (1.0.3)
23
- addressable (>= 2.2.3)
24
- cookiejar
25
- em-socksify
26
- eventmachine (>= 1.0.0.beta.4)
27
- http_parser.rb (>= 0.5.3)
28
- em-socksify (0.3.0)
21
+ diff-lcs (1.2.5)
22
+ em-hot_tub (1.1.0)
23
+ em-synchrony
24
+ hot_tub (~> 1.0.0)
25
+ em-http-request (1.1.3)
26
+ addressable (>= 2.3.4)
27
+ cookiejar (<= 0.3.0)
28
+ em-socksify (>= 0.3)
29
+ eventmachine (>= 1.0.3)
30
+ http_parser.rb (>= 0.6.0)
31
+ em-socksify (0.3.1)
29
32
  eventmachine (>= 1.0.0.beta.4)
30
- em-synchrony (1.0.3)
33
+ em-synchrony (1.0.4)
31
34
  eventmachine (>= 1.0.0.beta.1)
32
- eventmachine (1.0.3)
35
+ eventmachine (1.0.8)
33
36
  eventmachine_httpserver (0.2.1)
34
- hot_tub (0.2.6)
35
- http_parser.rb (0.5.3)
36
- json (1.8.0)
37
- nokogiri (1.5.10)
38
- rspec (2.13.0)
39
- rspec-core (~> 2.13.0)
40
- rspec-expectations (~> 2.13.0)
41
- rspec-mocks (~> 2.13.0)
42
- rspec-core (2.13.1)
43
- rspec-expectations (2.13.0)
44
- diff-lcs (>= 1.1.3, < 2.0)
45
- rspec-mocks (2.13.1)
46
- uuidtools (2.1.4)
37
+ hot_tub (1.0.0)
38
+ http_parser.rb (0.6.0)
39
+ json (1.8.3)
40
+ mini_portile2 (2.0.0)
41
+ nokogiri (1.6.7.1)
42
+ mini_portile2 (~> 2.0.0.rc2)
43
+ rake (10.4.2)
44
+ rspec (3.4.0)
45
+ rspec-core (~> 3.4.0)
46
+ rspec-expectations (~> 3.4.0)
47
+ rspec-mocks (~> 3.4.0)
48
+ rspec-autotest (1.0.0)
49
+ rspec-core (>= 2.99.0.beta1, < 4.0.0)
50
+ rspec-core (3.4.1)
51
+ rspec-support (~> 3.4.0)
52
+ rspec-expectations (3.4.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.4.0)
55
+ rspec-mocks (3.4.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.4.0)
58
+ rspec-support (3.4.1)
47
59
 
48
60
  PLATFORMS
49
61
  ruby
50
62
 
51
63
  DEPENDENCIES
52
- ZenTest (~> 4.8.2)
53
- builder
64
+ autotest
65
+ bundler (~> 1.7)
54
66
  em_aws!
55
67
  eventmachine_httpserver
68
+ rake
56
69
  rspec
70
+ rspec-autotest
71
+
72
+ BUNDLED WITH
73
+ 1.11.2
data/HISTORY.md CHANGED
@@ -4,14 +4,29 @@ EmAws Changelog
4
4
  HEAD
5
5
  =======
6
6
 
7
+ - None yet!
8
+
9
+ 1.0.0
10
+ =======
11
+
12
+ - Update to aws-skd-v1
13
+ - Update specs
14
+ - Use em-hot_tub
15
+ - Add integration tests
16
+ - EM style name space: require "em-aws"
17
+ - Support verify_response_body_content_length
18
+
19
+ 0.3.2
20
+ =======
21
+
7
22
  - check for Aws.config.logger when setting HotTub.logger [kybishop #21]
8
23
  - Clean up specs [kybishop #22]
9
24
 
10
25
  0.3.0
11
26
  =======
12
27
 
13
- - requires AWS-SDK 1.9.3 for thread saftey issues in 1.9.0-1.9.2
14
- - refactors client API to expose EM-Http-Request client options directly
28
+ - requires AWS-SDK 1.9.3 for thread safety issues in 1.9.0-1.9.2
29
+ - refactor client API to expose EM-Http-Request client options directly
15
30
 
16
31
  0.2.9
17
32
  =======
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2013 Joshua T. Mckinney
1
+ Copyright (c) 2010-2015 Joshua T. McKinney
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,20 +1,18 @@
1
- # EmAws
1
+ # EM::AWS [![Build Status](https://travis-ci.org/JoshMcKin/em_aws.svg)](https://travis-ci.org/JoshMcKin/em_aws)
2
2
  An EM-Synchrony handler for Ruby [AWS-SDK-Ruby](https://github.com/aws/aws-sdk-ruby)
3
3
  ## Installation
4
4
 
5
- em_aws is available through [Rubygems](https://rubygems.org/gems/em_aws) and can be installed via:
5
+ EM::AWS is available through [Rubygems](https://rubygems.org/gems/em_aws) and can be installed via:
6
6
 
7
7
  $ gem install em_aws
8
8
 
9
9
  ### Requirements
10
10
 
11
- * EmAws 0.3.x requires AWS-SDK-Ruby ~> 1.9.3
12
- * EmAws 0.2.x is available for those using AWS-SDK-Ruby <= 1.8.5
13
- * AWS-SDK-Ruby 1.9.0 to 1.9.2 are not compatible with any version of EmAws; see [here](https://github.com/aws/aws-sdk-ruby/issues/237)
11
+ * EmAws 0.4.x requires [AWS-SDK-v1](https://github.com/aws/aws-sdk-ruby/blob/aws-sdk-v1)
14
12
 
15
13
  ## Rails 3 setup
16
14
 
17
- Setup [AWS-SDK-Ruby](https://github.com/aws/aws-sdk-ruby/blob/master/README.rdoc) as you would normally.
15
+ Setup [AWS-SDK-Ruby](https://github.com/aws/aws-sdk-ruby/blob/aws-sdk-v1/README.md) as you would normally.
18
16
 
19
17
  Assuming you've already setup async-rails, add em_aws to your gemfile:
20
18
 
@@ -26,33 +24,21 @@ Then run:
26
24
 
27
25
  Add the following to your aws.rb initializer:
28
26
 
29
- require 'aws-sdk'
30
- require 'aws/core/http/em_http_handler'
31
- AWS.config(
32
- :http_handler => AWS::Http::EMHttpHandler.new(
33
- :proxy => { :host => '127.0.0.1', # proxy address
34
- :port => 9000, # proxy port
35
- :type => :socks5 },
36
- :pool_size => 20, # Default is 0, set to > 0 to enable pooling
37
- :async => false)) # If set to true all requests are handle asynchronously
38
- # and initially return nil
27
+ require 'em-aws'
28
+ AWS.config( :http_handler => EM::AWS::HttpHandler.new )
39
29
 
40
30
  You are done.
41
31
 
42
32
  All requests to AWS will use EM-Synchrony's implementation of em-http-request for non-block HTTP requests and fiber management. See [EM-HTTP-Request](https://github.com/igrigorik/em-http-request/wiki/Issuing-Requests#available-connection--request-parameters) for all client options
43
33
 
44
- ## Connection Pooling (keep-alive)
34
+ ## Connection Pooling (w/keep-alive)
45
35
 
46
- We use [HotTub](https://github.com/JoshMcKin/hot_tub) to manage connection pooling. To enable connection pooling set the :pool_size to anything greater than 0. By default :inactivity_timeout is set to 0 which will leave the connection open for as long as the client allows. Connects
47
- are created lazy, so pools grow until they meet the set pool size.
36
+ We use [EM-HotTub](https://github.com/JoshMcKin/em-hot_tub) to manage connection pooling. To enable connection pooling set the :pool_size to anything greater than 1, default is 5. By default :inactivity_timeout is set to 0 which will leave the connection open for as long as the AWS allows. Connections are created lazy, so pools grows to meet concurrency. If we need to limit our total number of connections we can set :max_size. HotTub will reap connections down to :pool_size when load dies.
48
37
 
49
- require 'aws-sdk'
50
- require 'aws/core/http/em_http_handler'
38
+ require 'em-aws'
51
39
  AWS.config(
52
- :http_handler => AWS::Http::EMHttpHandler.new({
53
- :pool_size => 20,
54
- :inactivity_timeout => 0, # number of seconds to timeout stale connections in the pool,
55
- :never_block => true) # if we run out of connections, create a new one
40
+ :http_handler => EM::AWS::HttpHandler.new({
41
+ :pool_size => 20, # default is 5, setting to 1 disables pool
56
42
  )
57
43
 
58
44
  ## Streaming
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
data/em_aws.gemspec CHANGED
@@ -1,26 +1,28 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "em_aws/version"
3
+ require "em-aws/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "em_aws"
7
- s.version = EmAws::VERSION
7
+ s.version = EventMachine::AWS::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Joshua Mckinney"]
10
10
  s.email = ["joshmckin@gmail.com"]
11
11
  s.homepage = "https://github.com/JoshMcKin/em_aws"
12
12
  s.license = "MIT"
13
13
  s.summary = %q{Adds EM-Synchrony support to AWS-SDK gem}
14
- s.description = %q{Adds EM-Synchrony support to AWS-SDK gem}
14
+ s.description = %q{An em-http-request handler for the aws-sdk for Fiber based asynchronous ruby application using EM-Synchrony}
15
15
 
16
16
  s.rubyforge_project = "em_aws"
17
17
 
18
- s.add_runtime_dependency "aws-sdk", ">= 1.9.3"
18
+ s.add_runtime_dependency 'aws-sdk-v1'
19
19
  s.add_runtime_dependency "em-synchrony"
20
20
  s.add_runtime_dependency "em-http-request"
21
- s.add_runtime_dependency "hot_tub", "~> 0.2.4"
21
+ s.add_runtime_dependency "em-hot_tub", "~> 1.1.0"
22
+ s.add_development_dependency "bundler", "~> 1.7"
22
23
  s.add_development_dependency "rspec"
23
- s.add_development_dependency "builder"
24
+ s.add_development_dependency "rspec-autotest"
25
+ s.add_development_dependency "autotest"
24
26
 
25
27
  s.files = `git ls-files`.split("\n")
26
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,205 +1,8 @@
1
- # http://docs.amazonwebservices.com/AWSRubySDK/latest/
2
- require 'hot_tub'
3
- require 'em-synchrony'
4
- require 'em-synchrony/em-http'
5
- require 'em-synchrony/thread'
1
+ require 'em-aws'
6
2
  module AWS
7
3
  module Core
8
4
  module Http
9
-
10
- # An EM-Synchrony implementation for Fiber based asynchronous ruby application.
11
- # See https://github.com/igrigorik/async-rails and
12
- # http://www.mikeperham.com/2010/04/03/introducing-phat-an-asynchronous-rails-app/
13
- # for examples of Aync-Rails application
14
- #
15
- # In Rails add the following to your aws.rb initializer
16
- #
17
- # require 'aws-sdk'
18
- # require 'aws/core/http/em_http_handler'
19
- # AWS.config(
20
- # :http_handler => AWS::Http::EMHttpHandler.new(
21
- # :proxy => {:host => '127.0.0.1', # proxy address
22
- # :port => 9000, # proxy port
23
- # :type => :socks5},
24
- # :pool_size => 20, # Default is 0, set to > 0 to enable pooling
25
- # :async => false)) # If set to true all requests are handle asynchronously
26
- # # and initially return nil
27
- #
28
- # EM-AWS exposes all connections options for EM-Http-Request at initialization
29
- # For more information on available options see https://github.com/igrigorik/em-http-request/wiki/Issuing-Requests#available-connection--request-parameters
30
- # If Options from the request section of the above link are present, they
31
- # set on every request but may be over written by the request object
32
- class EMHttpHandler
33
-
34
- EM_PASS_THROUGH_ERRORS = [
35
- NoMethodError, FloatDomainError, TypeError, NotImplementedError,
36
- SystemExit, Interrupt, SyntaxError, RangeError, NoMemoryError,
37
- ArgumentError, ZeroDivisionError, LoadError, NameError,
38
- LocalJumpError, SignalException, ScriptError,
39
- SystemStackError, RegexpError, IndexError,
40
- ]
41
-
42
- attr_reader :default_options, :client_options, :pool_options, :pool
43
-
44
- # Constructs a new HTTP handler using EM-Synchrony.
45
- # @param [Hash] options Default options to send to EM-Synchrony on
46
- # each request. These options will be sent to +get+, +post+,
47
- # +head+, +put+, or +delete+ when a request is made. Note
48
- # that +:body+, +:head+, +:parser+, and +:ssl_ca_file+ are
49
- # ignored. If you need to set the CA file see:
50
- # https://github.com/igrigorik/em-http-request/wiki/Issuing-Requests#available-connection--request-parameters
51
- def initialize options = {}
52
- @default_options = options
53
- @client_options = fetch_client_options
54
- @pool_options = fetch_pool_options
55
- @pool = HotTub::Session.new(pool_options) { |url|
56
- EM::HttpRequest.new(url,client_options)} if with_pool?
57
- end
58
-
59
- def handle(request,response,&read_block)
60
- if EM::reactor_running?
61
- process_request(request,response,&read_block)
62
- else
63
- EM.synchrony do
64
- process_request(request,response,&read_block)
65
- pool.close_all if pool
66
- EM.stop
67
- end
68
- end
69
- end
70
-
71
- # If the request option :async are set to true that request will handled
72
- # asynchronously returning nil initially and processing in the background
73
- # managed by EM-Synchrony. If the client option :async all requests will
74
- # be handled asynchronously.
75
- # EX:
76
- # EM.synchrony do
77
- # s3 = AWS::S3.new
78
- # s3.obj.write('test', :async => true) => nil
79
- # EM::Synchrony.sleep(2)
80
- # s3.obj.read => # 'test'
81
- # EM.stop
82
- # end
83
- def handle_async(request,response,handle,&read_block)
84
- if EM::reactor_running?
85
- process_request(request,response,true,&read_block)
86
- else
87
- EM.synchrony do
88
- process_request(request,response,true,&read_block)
89
- pool.close_all if @pool
90
- EM.stop
91
- end
92
- end
93
- end
94
-
95
- def with_pool?
96
- (default_options[:pool_size].to_i > 0)
97
- end
98
-
99
- private
100
-
101
- def fetch_client_options
102
- co = ({} || default_options.dup)
103
- co.delete(:pool_size)
104
- co.delete(:never_block)
105
- co.delete(:blocking_timeout)
106
- co[:inactivity_timeout] ||= 0
107
- co[:connect_timeout] ||= 10
108
- co[:keepalive] = true if with_pool?
109
- co
110
- end
111
-
112
- def fetch_pool_options
113
- {
114
- :with_pool => true,
115
- :size => ((default_options[:pool_size].to_i || 5)),
116
- :never_block => (default_options[:never_block].nil? ? true : default_options[:never_block]),
117
- :blocking_timeout => (default_options[:blocking_timeout] || 10)
118
- }
119
- end
120
-
121
- def fetch_url(request)
122
- "#{(request.use_ssl? ? "https" : "http")}://#{request.host}:#{request.port}"
123
- end
124
-
125
- def fetch_headers(request)
126
- headers = { 'content-type' => '' }
127
- request.headers.each_pair do |key,value|
128
- headers[key] = value.to_s
129
- end
130
- {:head => headers}
131
- end
132
-
133
- def fetch_request_options(request)
134
- opts = client_options.merge(fetch_headers(request))
135
- opts[:query] = request.querystring
136
- if request.body_stream.respond_to?(:path)
137
- opts[:file] = request.body_stream.path
138
- else
139
- opts[:body] = request.body.to_s
140
- end
141
- opts[:path] = request.path if request.path
142
- opts
143
- end
144
-
145
- def fetch_response(request,opts={},&read_block)
146
- method = "a#{request.http_method}".downcase.to_sym # aget, apost, aput, adelete, ahead
147
- url = fetch_url(request)
148
- if pool
149
- pool.run(url) do |connection|
150
- req = connection.send(method, opts)
151
- req.stream &read_block if block_given?
152
- return EM::Synchrony.sync req unless opts[:async]
153
- end
154
- else
155
- clnt_opts = client_options.merge(:inactivity_timeout => request.read_timeout)
156
- req = EM::HttpRequest.new(url,clnt_opts).send(method,opts)
157
- req.stream &read_block if block_given?
158
- return EM::Synchrony.sync req unless opts[:async]
159
- end
160
- nil
161
- end
162
-
163
- # AWS needs all header keys downcased and values need to be arrays
164
- def fetch_response_headers(response)
165
- response_headers = response.response_header.raw.to_hash
166
- aws_headers = {}
167
- response_headers.each_pair do |k,v|
168
- key = k.downcase
169
- #['x-amz-crc32', 'x-amz-expiration','x-amz-restore','x-amzn-errortype']
170
- if v.is_a?(Array)
171
- aws_headers[key] = v
172
- else
173
- aws_headers[key] = [v]
174
- end
175
- end
176
- response_headers.merge(aws_headers)
177
- end
178
-
179
- # Builds and attempts the request. Occasionally under load em-http-request
180
- # em-http-request returns a status of 0 for various http timeouts, see:
181
- # https://github.com/igrigorik/em-http-request/issues/76
182
- # https://github.com/eventmachine/eventmachine/issues/175
183
- def process_request(request,response,async=false,&read_block)
184
- opts = fetch_request_options(request)
185
- opts[:async] = (async || opts[:async])
186
- begin
187
- http_response = fetch_response(request,opts,&read_block)
188
- unless opts[:async]
189
- response.status = http_response.response_header.status.to_i
190
- raise Timeout::Error if response.status == 0
191
- response.headers = fetch_response_headers(http_response)
192
- response.body = http_response.response
193
- end
194
- rescue Timeout::Error => error
195
- response.network_error = error
196
- rescue *EM_PASS_THROUGH_ERRORS => error
197
- raise error
198
- rescue Exception => error
199
- response.network_error = error
200
- end
201
- nil
202
- end
5
+ class EMHttpHandler < EM::AWS::HttpHandler
203
6
  end
204
7
  end
205
8
  end