xpool 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- == HEAD
1
+ == v0.11.0
2
2
  - no longer log from trap(…) block.
3
3
  the logger cannot log from within a trap block on Ruby2, so I've removed
4
4
  logging when a subprocess gets a request to shutdown.
data/README.md CHANGED
@@ -29,7 +29,7 @@ pool with five subprocesses and schedule a unit of work five times, each
29
29
  subprocess in the pool would have executed the unit of work once.
30
30
 
31
31
  A pool can become "dry" whenever all its subprocesses are busy. If you schedule
32
- a unit of work on a dry pool the same scheduling logic apllies but instead of
32
+ a unit of work on a dry pool the same scheduling logic applies but instead of
33
33
  the unit of work executing right away it will be executed whenever the
34
34
  assigned subprocess is no longer busy. It is also possible to query the pool
35
35
  and ask if it is dry, but you can also ask an individual subprocess if it is
@@ -109,27 +109,6 @@ pool.broadcast Unit.new
109
109
  pool.shutdown
110
110
  ```
111
111
 
112
- __DEBUGGING OUTPUT__
113
-
114
- xpool can print helpful debugging information if you set `XPool.debug`
115
- to true:
116
-
117
- ```ruby
118
- XPool.debug = true
119
- ```
120
-
121
- Or you can temporarily enable debugging output for the duration of a block:
122
-
123
- ```ruby
124
- XPool.debug do
125
- pool = XPool.new 2
126
- pool.shutdown
127
- end
128
- ```
129
-
130
- The debugging information you'll see is all about how the pool is operating.
131
- It can be interesting to look over even if you're not bug hunting.
132
-
133
112
  __SIGUSR1__
134
113
 
135
114
  All xpool managed subprocesses define a signal handler for the SIGUSR1 signal.
@@ -0,0 +1,18 @@
1
+ __DEBUGGING__
2
+
3
+ xpool can print helpful debugging information if you set `XPool.debug`
4
+ to true. The debugging information you'll see is all about how the pool is
5
+ operating. It can be interesting to look over even if you're not bug hunting.
6
+
7
+ ```ruby
8
+ XPool.debug = true
9
+ ```
10
+
11
+ Or you can temporarily enable debugging output for the duration of a block:
12
+
13
+ ```ruby
14
+ XPool.debug do
15
+ pool = XPool.new 2
16
+ pool.shutdown
17
+ end
18
+ ```
@@ -239,11 +239,6 @@ private
239
239
  end
240
240
 
241
241
  def _resize(new_size, with_force)
242
- if Range === new_size
243
- warn "[DEPRECATED] XPool#resize! no longer accepts a Range." \
244
- "Please use a Fixnum instead."
245
- new_size = range.to_a.size
246
- end
247
242
  new_size -= 1
248
243
  old_size = size - 1
249
244
  if new_size == old_size
@@ -164,22 +164,22 @@ private
164
164
 
165
165
  def spawn
166
166
  fork do
167
- trap :SIGUSR1 do
168
- XPool.log "#{::Process.pid} got request to shutdown."
169
- @shutdown_requested = true
170
- end
167
+ trap(:SIGUSR1) { @shutdown_requested = true }
171
168
  loop &method(:read_loop)
172
169
  end
173
170
  end
174
171
 
175
172
  def read_loop
176
173
  if @channel.readable?
174
+ @frequency += 1
177
175
  @s_channel.put busy: true
178
176
  msg = @channel.get
177
+ msg[:unit].setup if @frequency == 1 && msg[:unit].respond_to?(:setup)
179
178
  msg[:unit].run *msg[:args]
180
179
  @s_channel.put busy: false
180
+ else
181
+ sleep 0.05
181
182
  end
182
- sleep 0.05
183
183
  rescue Exception => e
184
184
  @s_channel.put failed: true, dead: true, backtrace: e.backtrace
185
185
  XPool.log "Process with ID '#{@id}' has failed."
@@ -1,3 +1,3 @@
1
1
  class XPool
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -14,7 +14,7 @@ class XPoolProcessTest < Test::Unit::TestCase
14
14
  io_writers.each { |writer| @process.schedule writer }
15
15
  until @process.failed?; sleep 0.1; end
16
16
  @process.restart
17
- sleep 0.5
17
+ sleep 0.1
18
18
  io_writers.each { |io_writer| assert io_writer.wrote_to_disk? }
19
19
  end
20
20
 
@@ -26,6 +26,16 @@ class XPoolProcessTest < Test::Unit::TestCase
26
26
  refute @process.busy?, 'Expected process to not be busy'
27
27
  end
28
28
 
29
+ def test_call_of_setup
30
+ writer = IOSetupWriter.new
31
+ @process.schedule writer
32
+ sleep 0.1
33
+ assert writer.wrote_to_disk?
34
+ @process.schedule writer
35
+ sleep 0.1
36
+ refute writer.wrote_to_disk?
37
+ end
38
+
29
39
  def test_busy_on_exception
30
40
  @process.schedule Raiser.new
31
41
  sleep 0.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xpool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,6 +45,7 @@ files:
45
45
  - Rakefile
46
46
  - bench/.gitkeep
47
47
  - bench/pool-schedule.rb
48
+ - docs/debugging.md
48
49
  - docs/unhandled_exceptions.md
49
50
  - lib/xpool.rb
50
51
  - lib/xpool/process.rb
@@ -70,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
71
  version: '0'
71
72
  segments:
72
73
  - 0
73
- hash: -3457064609731373945
74
+ hash: 3959300438831349653
74
75
  required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  none: false
76
77
  requirements:
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  segments:
81
82
  - 0
82
- hash: -3457064609731373945
83
+ hash: 3959300438831349653
83
84
  requirements: []
84
85
  rubyforge_project:
85
86
  rubygems_version: 1.8.23