rack-fiber_pool 0.9.1 → 0.9.2

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.
data/README.md CHANGED
@@ -4,7 +4,7 @@ rack-fiber_pool
4
4
  A Rack middleware component which runs each request in a Fiber from a pool of Fibers.
5
5
 
6
6
  Requirements
7
- ==============
7
+ ============
8
8
 
9
9
  * Ruby 1.9
10
10
  * EventMachine-based server (e.g. thin or rainbows)
@@ -16,9 +16,20 @@ Add a require and use statement to your Rack app. See example/app.rb for a simp
16
16
  which illustrates proper usage. In general, you want the FiberPool to be inserted as early as
17
17
  possible in the middleware pipeline.
18
18
 
19
+ Options
20
+ =======
21
+
22
+ You may fix the pool size, otherwise it defaults to 100:
23
+
24
+ use Rack::FiberPool, :size => 25
25
+
26
+ All exceptions raised by request handled within a fiber are rescued, by default returning a 500 with no body content. You may customize exceptions rescuing by providing a Proc object conforming to Rack's API:
27
+
28
+ rescue_exception = Proc.new { |env, exception| [503, {}, exception.message] }
29
+ use Rack::FiberPool, :rescue_exception => rescue_exception
19
30
 
20
31
  Rails
21
- ========
32
+ =====
22
33
 
23
34
  You can see your app's current pipeline of Rack middleware using:
24
35
 
@@ -39,7 +50,7 @@ You can explicitly place the FiberPool like so:
39
50
 
40
51
  ActionController::Dispatcher.middleware.insert_before ActionController::Session::CookieStore, Rack::FiberPool
41
52
 
42
-
53
+
43
54
  Thanks to
44
55
  ==========
45
56
 
@@ -47,6 +58,6 @@ Eric Wong - for adding explicit support for Rack::FiberPool to rainbows.
47
58
 
48
59
 
49
60
  Author
50
- =========
61
+ ======
51
62
 
52
- Mike Perham, [Twitter](http://twitter.com/mperham), [Github](http://github.com/mperham), mperham AT gmail.com.
63
+ Mike Perham, [Twitter](http://twitter.com/mperham), [Github](http://github.com/mperham), mperham AT gmail.com.
@@ -2,7 +2,7 @@ require 'fiber_pool'
2
2
 
3
3
  module Rack
4
4
  class FiberPool
5
- VERSION = '0.9.1'
5
+ VERSION = '0.9.2'
6
6
  SIZE = 100
7
7
 
8
8
  # The size of the pool is configurable:
@@ -11,17 +11,22 @@ module Rack
11
11
  def initialize(app, options={})
12
12
  @app = app
13
13
  @fiber_pool = ::FiberPool.new(options[:size] || SIZE)
14
+ @rescue_exception = options[:rescue_exception] || Proc.new { |env, e| [500, {}, "#{e.class.name}: #{e.message.to_s}"] }
14
15
  yield @fiber_pool if block_given?
15
16
  end
16
17
 
17
18
  def call(env)
18
19
  call_app = lambda do
19
- result = @app.call(env)
20
- env['async.callback'].call result
20
+ begin
21
+ result = @app.call(env)
22
+ env['async.callback'].call result
23
+ rescue ::Exception => e
24
+ env['async.callback'].call @rescue_exception.call(env, e)
25
+ end
21
26
  end
22
-
27
+
23
28
  @fiber_pool.spawn(&call_app)
24
29
  throw :async
25
30
  end
26
31
  end
27
- end
32
+ end
@@ -17,7 +17,32 @@ class TestRackFiberPool < MiniTest::Unit::TestCase
17
17
  end
18
18
  assert_equal [200, {"Content-Type"=>"text/plain"}, ["Hello world!"]], app.result
19
19
  end
20
-
20
+
21
+ def test_exception
22
+ app = TestBuggyApp.new
23
+ catch :async do
24
+ res = Rack::MockRequest.new(Rack::FiberPool.new(app)).get("/")
25
+ end
26
+ assert_equal [500, {}, "Exception: I'm buggy! Please fix me."], app.result
27
+ end
28
+
29
+ def test_custom_rescue_exception
30
+ app = TestBuggyApp.new
31
+ catch :async do
32
+ rescue_exception = Proc.new { |env, exception| [503, {}, exception.message] }
33
+ res = Rack::MockRequest.new(Rack::FiberPool.new(app, :rescue_exception => rescue_exception)).get('/')
34
+ end
35
+ assert_equal [503, {}, "I'm buggy! Please fix me."], app.result
36
+ end
37
+
38
+ class TestBuggyApp
39
+ attr_accessor :result
40
+ def call(env)
41
+ env['async.callback'] = proc { |result| @result = result }
42
+ raise Exception.new("I'm buggy! Please fix me.")
43
+ end
44
+ end
45
+
21
46
  class TestApp
22
47
  attr_accessor :result
23
48
  def call(env)
metadata CHANGED
@@ -1,32 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-fiber_pool
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 1
9
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Mike Perham
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-14 00:00:00 -08:00
12
+ date: 2011-08-24 00:00:00.000000000 -07:00
18
13
  default_executable:
19
14
  dependencies: []
20
-
21
15
  description: Rack middleware to run each request within a Fiber
22
16
  email: mperham@gmail.com
23
17
  executables: []
24
-
25
18
  extensions: []
26
-
27
19
  extra_rdoc_files: []
28
-
29
- files:
20
+ files:
30
21
  - LICENSE
31
22
  - README.md
32
23
  - Rakefile
@@ -38,35 +29,29 @@ files:
38
29
  has_rdoc: true
39
30
  homepage: http://github.com/mperham/rack-fiber_pool
40
31
  licenses: []
41
-
42
32
  post_install_message:
43
- rdoc_options:
33
+ rdoc_options:
44
34
  - --charset=UTF-8
45
- require_paths:
35
+ require_paths:
46
36
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
37
+ required_ruby_version: !ruby/object:Gem::Requirement
48
38
  none: false
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- version: "0"
55
- required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
44
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- version: "0"
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
63
49
  requirements: []
64
-
65
50
  rubyforge_project:
66
- rubygems_version: 1.3.7
51
+ rubygems_version: 1.6.2
67
52
  signing_key:
68
53
  specification_version: 3
69
54
  summary: Rack middleware to run each request within a Fiber
70
- test_files:
55
+ test_files:
71
56
  - test/helper.rb
72
57
  - test/test_rack-fiber_pool.rb