em_aws 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- em_aws (0.1.0)
4
+ em_aws (0.1.1)
5
5
  aws-sdk
6
6
  em-http-request
7
7
  em-synchrony
data/README.md CHANGED
@@ -27,7 +27,6 @@ In your environments files add:
27
27
  require 'aws/core/http/em_http_handler'
28
28
  AWS.config(
29
29
  :http_handler => AWS::Http::EMHttpHandler.new(
30
- :pool_size => 5,
31
30
  :proxy => {:host => "http://myproxy.com", :port => 80}
32
31
  ))
33
32
 
@@ -35,25 +34,6 @@ Your done.
35
34
 
36
35
  All requests to AWS will use EM-Synchrony's implementation of em-http-request for non-block HTTP request and fiber management.
37
36
 
38
- ## Connection Pools
39
- v0.1+ implement connections EventMachine::Synchrony::ConnectionPool. The default pool_size is 5 but it can be
40
- increased by in the AWS.config options. Connection pools were problematic for S3 calls that required the :path option for
41
- em-http-request and would return AWS::S3::SignatureDoesNotMatch errors; so for now S3 calls with paths do not make use of the connection pools.
42
-
43
- ## Heroku Gotcha
44
- When deploying to Heroku, if you get "NameError: uninitialized constant Syck::Syck", you need to vendorize em_aws
45
-
46
- From your apps root directory run:
47
-
48
- gem unpack em_aws --target vendor/gems
49
-
50
- Update you gemfile:
51
-
52
- gem 'em_aws', :path => "vendor/gems/em_aws-0.0.3"
53
-
54
- Finally, run bundler and make sure you check-in your new Gemfile.lock.
55
- I'm pretty sure the Syck error is do to an outdated version of rubygems and bundler on Heroku, but as of yet have not been able to reproduce it locally.
56
-
57
37
  ## References
58
38
 
59
39
  [aws-sdk](https://github.com/amazonwebservices/aws-sdk-for-ruby)
@@ -18,7 +18,6 @@ module AWS
18
18
  # require 'aws/core/http/em_http_handler'
19
19
  # AWS.config(
20
20
  # :http_handler => AWS::Http::EMHttpHandler.new(
21
- # :pool_size => 20,
22
21
  # :proxy => {:host => "http://myproxy.com",:port => 80}
23
22
  # )
24
23
  # )
@@ -27,14 +26,6 @@ module AWS
27
26
  # @return [Hash] The default options to send to EM-Synchrony on each
28
27
  # request.
29
28
  attr_reader :default_request_options
30
- @@pools = {}
31
-
32
- def self.fetch_connection(url,pool_size)
33
- @@pools[url] ||= EventMachine::Synchrony::ConnectionPool.new(size: pool_size) do
34
- EM::HttpRequest.new(url)
35
- end
36
- @@pools[url]
37
- end
38
29
 
39
30
  # Constructs a new HTTP handler using EM-Synchrony.
40
31
  #
@@ -48,16 +39,15 @@ module AWS
48
39
  # Defaults pool_size to 5
49
40
  def initialize options = {}
50
41
  #puts "Using EM-Synchrony for AWS requests"
51
- options[:pool_size] ||= 5
52
42
  @default_request_options = options
53
43
  end
54
44
 
55
45
  def fetch_url(request)
56
46
  url = nil
57
47
  if request.use_ssl?
58
- url = "https://#{request.host}:443"
48
+ url = "https://#{request.host}:443#{request.uri}"
59
49
  else
60
- url = "http://#{request.host}"
50
+ url = "http://#{request.host}#{request.uri}"
61
51
  end
62
52
  url
63
53
  end
@@ -101,25 +91,15 @@ module AWS
101
91
  # We get AWS::S3::SignatureDoesNotMatch when path is used to fetch an s3 object
102
92
  # so for now we won't use the pool for requests where the path is more than just '/'
103
93
  def fetch_response(url,method,opts={})
104
- return EM::HttpRequest.new("#{url}#{opts[:path]}").send(method, opts) if (@default_request_options[:pool_size] == 0 || opts[:path].to_s.length > 1)
105
- self.class.fetch_connection(url,@default_request_options[:pool_size]).send(method, opts)
106
- end
107
-
108
- # Add thread safety.
109
- def _fibered_mutex
110
- @fibered_mutex ||= EM::Synchrony::Thread::Mutex.new
94
+ return EM::HttpRequest.new("#{url}").send(method, opts)
111
95
  end
112
-
96
+
113
97
  def handle(request,response)
114
- if EM::reactor_running?
115
- _fibered_mutex.synchronize do
116
- handle_it(request, response)
117
- end
98
+ if EM::reactor_running?
99
+ handle_it(request, response)
118
100
  else
119
101
  EM.synchrony do
120
- _fibered_mutex.synchronize do
121
- handle_it(request, response)
122
- end
102
+ handle_it(request, response)
123
103
  EM.stop
124
104
  end
125
105
  end
@@ -127,14 +107,19 @@ module AWS
127
107
 
128
108
  def handle_it(request, response)
129
109
  #puts "Using EM!!!!"
130
- opts = default_request_options.merge({
131
- :body => request.body,
132
- :path => request.uri,
133
-
134
- }).merge(request_options(request))
135
- url = fetch_url(request)
136
110
  # get, post, put, delete, head
137
- method = request.http_method.downcase
111
+ method = request.http_method.downcase.to_sym
112
+
113
+ opts = default_request_options.
114
+ merge(request_options(request))
115
+ if (method == :get)
116
+ opts[:query] = request.body
117
+ else
118
+ opts[:body] = request.body
119
+ end
120
+
121
+ url = fetch_url(request)
122
+
138
123
  begin
139
124
  http_response = fetch_response(url,method,opts)
140
125
  rescue Timeout::Error, Errno::ETIMEDOUT => e
@@ -1,3 +1,3 @@
1
1
  module EmAws
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -48,17 +48,10 @@ module AWS::Core
48
48
  end
49
49
 
50
50
  describe '#initialize' do
51
-
52
51
  it 'should set the default request options' do
53
52
  described_class.new(:foo => "BAR").default_request_options.
54
- should == { :foo => "BAR", :pool_size => 5 }
55
- end
56
-
57
- it 'should not override supplied pool_size' do
58
- described_class.new(:pool_size => 20).default_request_options.
59
- should == { :pool_size => 20 }
53
+ should == { :foo => "BAR" }
60
54
  end
61
-
62
55
  end
63
56
 
64
57
  describe '#handle' do
@@ -160,4 +153,4 @@ module AWS::Core
160
153
  end
161
154
  end
162
155
  end
163
- end
156
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
16
- requirement: &70247639340500 !ruby/object:Gem::Requirement
16
+ requirement: &70103158270460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70247639340500
24
+ version_requirements: *70103158270460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-synchrony
27
- requirement: &70247639339960 !ruby/object:Gem::Requirement
27
+ requirement: &70103158269980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70247639339960
35
+ version_requirements: *70103158269980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-http-request
38
- requirement: &70247639339420 !ruby/object:Gem::Requirement
38
+ requirement: &70103158269520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70247639339420
46
+ version_requirements: *70103158269520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70247639338880 !ruby/object:Gem::Requirement
49
+ requirement: &70103158269100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70247639338880
57
+ version_requirements: *70103158269100
58
58
  description: Adds EM-Synchrony support to AWS-SDK gem
59
59
  email:
60
60
  - joshmckin@gmail.com