ringleader 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ require 'sys/proctable'
16
16
  module Ringleader
17
17
  end
18
18
 
19
+ require 'ringleader/celluloid_fix'
19
20
  require "ringleader/config"
20
21
  require "ringleader/name_logger"
21
22
  require "ringleader/wait_for_exit"
@@ -0,0 +1,139 @@
1
+ # FIXME: see zerowidth/ringleader#36 and celluloid/celluloid-io#23. If the
2
+ # celluloid issue is ever merged, this monkeypatch / wholesale rewrite needs to
3
+ # go away.
4
+
5
+ require 'nio'
6
+
7
+ module Celluloid
8
+ module IO
9
+ # React to external I/O events. This is kinda sorta supposed to resemble the
10
+ # Reactor design pattern.
11
+ class Reactor
12
+ extend Forwardable
13
+
14
+ # Unblock the reactor (i.e. to signal it from another thread)
15
+ def_delegator :@selector, :wakeup
16
+ # Terminate the reactor
17
+ def_delegator :@selector, :close, :shutdown
18
+
19
+ def initialize
20
+ @selector = NIO::Selector.new
21
+ @monitors = {}
22
+ end
23
+
24
+ # Wait for the given IO object to become readable
25
+ def wait_readable(io)
26
+ wait io do |monitor|
27
+ monitor.wait_readable
28
+ end
29
+ end
30
+
31
+ # Wait for the given IO object to become writable
32
+ def wait_writable(io)
33
+ wait io do |monitor|
34
+ monitor.wait_writable
35
+ end
36
+ end
37
+
38
+ # Wait for the given IO operation to complete
39
+ def wait(io)
40
+ # zomg ugly type conversion :(
41
+ unless io.is_a?(::IO) or io.is_a?(OpenSSL::SSL::SSLSocket)
42
+ if io.respond_to? :to_io
43
+ io = io.to_io
44
+ elsif ::IO.respond_to? :try_convert
45
+ io = ::IO.try_convert(io)
46
+ end
47
+
48
+ raise TypeError, "can't convert #{io.class} into IO" unless io.is_a?(::IO)
49
+ end
50
+
51
+ unless monitor = @monitors[io]
52
+ monitor = Monitor.new(@selector, io)
53
+ @monitors[io] = monitor
54
+ end
55
+
56
+ yield monitor
57
+ end
58
+
59
+ # Run the reactor, waiting for events or wakeup signal
60
+ def run_once(timeout = nil)
61
+ @selector.select(timeout) do |monitor|
62
+ monitor.value.resume
63
+ end
64
+ end
65
+
66
+ class Monitor
67
+ def initialize(selector, io)
68
+ @selector = selector
69
+ @io = io
70
+ @interests = {}
71
+ end
72
+
73
+ def wait_readable
74
+ wait :r
75
+ end
76
+
77
+ def wait_writable
78
+ wait :w
79
+ end
80
+
81
+ def wait(interest)
82
+ raise "Already waiting for #{interest.inspect}" if @interests.include?(interest)
83
+ @interests[interest] = Task.current
84
+ reregister
85
+ Task.suspend :iowait
86
+ end
87
+
88
+ def reregister
89
+ if @monitor
90
+ @monitor.close
91
+ @monitor = nil
92
+ end
93
+
94
+ if interests_symbol
95
+ @monitor = @selector.register(@io, interests_symbol)
96
+ @monitor.value = self
97
+ end
98
+ end
99
+
100
+ def interests_symbol
101
+ case @interests.keys
102
+ when [:r]
103
+ :r
104
+ when [:w]
105
+ :w
106
+ when [:r, :w]
107
+ :rw
108
+ end
109
+ end
110
+
111
+ def resume
112
+ raise "No monitor" unless @monitor
113
+
114
+ if @monitor.readable?
115
+ resume_for :r
116
+ end
117
+
118
+ if @monitor.writable?
119
+ resume_for :w
120
+ end
121
+
122
+ reregister
123
+ end
124
+
125
+ def resume_for(interest)
126
+ task = @interests.delete(interest)
127
+
128
+ if task
129
+ if task.running?
130
+ task.resume
131
+ else
132
+ raise "reactor attempted to resume a dead task"
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
@@ -1,3 +1,3 @@
1
1
  module Ringleader
2
- VERSION = "1.1.7"
2
+ VERSION = "1.1.8"
3
3
  end
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Ringleader::VERSION
17
17
  gem.required_ruby_version = "> 1.9.3"
18
18
 
19
- gem.add_dependency "celluloid", "~> 0.14.0"
20
- gem.add_dependency "celluloid-io", "~> 0.14.0"
19
+ gem.add_dependency "celluloid", "~> 0.15.0"
20
+ gem.add_dependency "celluloid-io", "~> 0.15.0"
21
21
  gem.add_dependency "reel", "~> 0.3.0"
22
22
  gem.add_dependency "trollop", "~> 1.16.2"
23
23
  gem.add_dependency "rainbow", "~> 1.1.4"
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  chruby_app:
3
- dir: "~/apps/main"
3
+ dir: "/Users/demo/apps/main"
4
4
  chruby: "foreman start"
5
5
  server_port: 3000
6
6
  app_port: 4000
@@ -86,7 +86,7 @@ describe Ringleader::Config do
86
86
  context "with a config with an 'chruby' key instead of a 'command'" do
87
87
  it "replaces the command with a command to use chruby" do
88
88
  config = Ringleader::Config.new "spec/fixtures/chruby.yml"
89
- expect(config.apps["chruby_app"].command).to eq("source /usr/local/share/chruby/chruby.sh ; source /usr/local/share/chruby/auto.sh ; cd /Users/tapajos/apps/main ; foreman start")
89
+ expect(config.apps["chruby_app"].command).to eq("source /usr/local/share/chruby/chruby.sh ; source /usr/local/share/chruby/auto.sh ; cd /Users/demo/apps/main ; foreman start")
90
90
  end
91
91
  end
92
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ringleader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-03 00:00:00.000000000 Z
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.14.0
21
+ version: 0.15.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.14.0
29
+ version: 0.15.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: celluloid-io
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.14.0
37
+ version: 0.15.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.14.0
45
+ version: 0.15.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: reel
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +237,7 @@ files:
237
237
  - lib/ringleader.rb
238
238
  - lib/ringleader/app.rb
239
239
  - lib/ringleader/app_serializer.rb
240
+ - lib/ringleader/celluloid_fix.rb
240
241
  - lib/ringleader/cli.rb
241
242
  - lib/ringleader/config.rb
242
243
  - lib/ringleader/controller.rb
@@ -278,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
279
  version: '0'
279
280
  segments:
280
281
  - 0
281
- hash: 540788086839220184
282
+ hash: 2596261918463299872
282
283
  requirements: []
283
284
  rubyforge_project:
284
285
  rubygems_version: 1.8.23