resque-pool 0.4.0.rc1 → 0.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05af825a91f84b2401987a45cc96b8e9fc520ac5
4
- data.tar.gz: 052428aeaaa748cc7a7475d027c2f1c11cdd23ff
3
+ metadata.gz: 0c09d6a6f29e55d9b78db9d4ab9b20fc7c4d6ff8
4
+ data.tar.gz: a1bad283f4cd04efa34d8a3d3651e27dca80af88
5
5
  SHA512:
6
- metadata.gz: 48239da0f9638eac69e7b370a348541e52d8850051917a45cda7cd9ee4977d75ebf41f6a8796df0df93a65fa48a56f9a46409cb87f273061c7bf4cff90b53af9
7
- data.tar.gz: c3404b991a0c5bb116672171d93dc48d123dd02c620da40ea274abf6b51ad02475524a8c3a577e75cd9c1c12f8fffc62aa60bf5878dc978e50a835ff3f87f197
6
+ metadata.gz: 4b0c682b1dfeed43223a616adae8ed7ec6847dc7099f515ea16d0e39f2c295879c652ef36a08e24f6704ca20559614bfb02ab4b04150af296ecd55990cc309b3
7
+ data.tar.gz: fb9a994b4f8454279e9a3e21a3d0f3faac7cb6b74ffe0a6711b8ba063d5e0208ec2a24960240b33b17291ccc1ffbaadab2f05f71f6a2bff1c075129e9aba2a9c
@@ -41,6 +41,7 @@ where [options] are:
41
41
  opt :term_graceful_wait, "On TERM signal, wait for workers to shut down gracefully"
42
42
  opt :term_graceful, "On TERM signal, shut down workers gracefully"
43
43
  opt :term_immediate, "On TERM signal, shut down workers immediately (default)"
44
+ opt :single_process_group, "Workers remain in the same process group as the master", :default => false
44
45
  end
45
46
  if opts[:daemon]
46
47
  opts[:stdout] ||= "log/resque-pool.stdout.log"
@@ -120,6 +121,7 @@ where [options] are:
120
121
  ENV["RACK_ENV"] = ENV["RAILS_ENV"] = ENV["RESQUE_ENV"] = opts[:environment] if opts[:environment]
121
122
  Resque::Pool.log "Resque Pool running in #{ENV["RAILS_ENV"] || "development"} environment"
122
123
  ENV["RESQUE_POOL_CONFIG"] = opts[:config] if opts[:config]
124
+ Resque::Pool.single_process_group = opts[:single_process_group]
123
125
  end
124
126
 
125
127
  def start_pool
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  class Pool
3
- VERSION = "0.4.0.rc1"
3
+ VERSION = "0.4.0.rc2"
4
4
  end
5
5
  end
data/lib/resque/pool.rb CHANGED
@@ -28,24 +28,31 @@ module Resque
28
28
 
29
29
  # Config: after_prefork {{{
30
30
 
31
- # The `after_prefork` hook will be run in workers if you are using the
32
- # preforking master worker to save memory. Use this hook to reload
31
+ # The `after_prefork` hooks will be run in workers if you are using the
32
+ # preforking master worker to save memory. Use these hooks to reload
33
33
  # database connections and so forth to ensure that they're not shared
34
34
  # among workers.
35
35
  #
36
- # Call with a block to set the hook.
37
- # Call with no arguments to return the hook.
36
+ # Call with a block to set a hook.
37
+ # Call with no arguments to return all registered hooks.
38
+ #
38
39
  def self.after_prefork(&block)
39
- block ? (@after_prefork = block) : @after_prefork
40
+ @after_prefork ||= []
41
+ block ? (@after_prefork << block) : @after_prefork
40
42
  end
41
43
 
42
- # Set the after_prefork proc.
44
+ # Sets the after_prefork proc, clearing all pre-existing hooks.
45
+ # Warning: you probably don't want to clear out the other hooks.
46
+ # You can use `Resque::Pool.after_prefork << my_hook` instead.
47
+ #
43
48
  def self.after_prefork=(after_prefork)
44
- @after_prefork = after_prefork
49
+ @after_prefork = [after_prefork]
45
50
  end
46
51
 
47
52
  def call_after_prefork!
48
- self.class.after_prefork && self.class.after_prefork.call
53
+ self.class.after_prefork.each do |hook|
54
+ hook.call
55
+ end
49
56
  end
50
57
 
51
58
  # }}}
@@ -65,6 +72,15 @@ module Resque
65
72
  @handle_winch = bool
66
73
  end
67
74
 
75
+ def self.single_process_group=(bool)
76
+ ENV["RESQUE_SINGLE_PGRP"] = !!bool ? "YES" : "NO"
77
+ end
78
+ def self.single_process_group
79
+ %w[yes y true t 1 okay sure please].include?(
80
+ ENV["RESQUE_SINGLE_PGRP"].to_s.downcase
81
+ )
82
+ end
83
+
68
84
  def self.choose_config_file
69
85
  if ENV["RESQUE_POOL_CONFIG"]
70
86
  ENV["RESQUE_POOL_CONFIG"]
@@ -380,6 +396,7 @@ module Resque
380
396
  def spawn_worker!(queues)
381
397
  worker = create_worker(queues)
382
398
  pid = fork do
399
+ Process.setpgrp unless Resque::Pool.single_process_group
383
400
  log_worker "Starting worker #{worker}"
384
401
  call_after_prefork!
385
402
  reset_sig_handlers!
@@ -394,8 +411,12 @@ module Resque
394
411
  worker = ::Resque::Worker.new(*queues)
395
412
  worker.term_timeout = ENV['RESQUE_TERM_TIMEOUT'] || 4.0
396
413
  worker.term_child = ENV['TERM_CHILD']
397
- worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
398
- worker.very_verbose = ENV['VVERBOSE']
414
+ if ENV['LOGGING'] || ENV['VERBOSE']
415
+ worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
416
+ end
417
+ if ENV['VVERBOSE']
418
+ worker.very_verbose = ENV['VVERBOSE']
419
+ end
399
420
  worker
400
421
  end
401
422
 
@@ -6,6 +6,7 @@ RSpec.configure do |config|
6
6
  ENV.delete 'RACK_ENV'
7
7
  ENV.delete 'RAILS_ENV'
8
8
  ENV.delete 'RESQUE_ENV'
9
+ ENV.delete 'RESQUE_POOL_CONFIG'
9
10
  }
10
11
  end
11
12
 
@@ -164,3 +165,38 @@ describe Resque::Pool, "when loading the pool configuration from a file" do
164
165
  end
165
166
 
166
167
  end
168
+
169
+ describe Resque::Pool, "given after_prefork hook" do
170
+ subject { Resque::Pool.new(nil) }
171
+
172
+ context "with a single hook" do
173
+ before { Resque::Pool.after_prefork { @called = true } }
174
+
175
+ it "should call prefork" do
176
+ subject.call_after_prefork!
177
+ @called.should == true
178
+ end
179
+ end
180
+
181
+ context "with a single hook by attribute writer" do
182
+ before { Resque::Pool.after_prefork = Proc.new { @called = true } }
183
+
184
+ it "should call prefork" do
185
+ subject.call_after_prefork!
186
+ @called.should == true
187
+ end
188
+ end
189
+
190
+ context "with multiple hooks" do
191
+ before {
192
+ Resque::Pool.after_prefork { @called_first = true }
193
+ Resque::Pool.after_prefork { @called_second = true }
194
+ }
195
+
196
+ it "should call both" do
197
+ subject.call_after_prefork!
198
+ @called_first.should == true
199
+ @called_second.should == true
200
+ end
201
+ end
202
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc1
4
+ version: 0.4.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nicholas a. evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 2.10.0
61
+ version: '2.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 2.10.0
68
+ version: '2.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 1.2.0
75
+ version: '1.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: 1.2.0
82
+ version: '1.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: aruba
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -158,7 +158,8 @@ files:
158
158
  - spec/resque-pool-custom.yml.erb
159
159
  - spec/resque_pool_spec.rb
160
160
  homepage: http://github.com/nevans/resque-pool
161
- licenses: []
161
+ licenses:
162
+ - MIT
162
163
  metadata: {}
163
164
  post_install_message:
164
165
  rdoc_options: []