resque-pool 0.4.0.rc2 → 0.4.0.rc3

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: 0c09d6a6f29e55d9b78db9d4ab9b20fc7c4d6ff8
4
- data.tar.gz: a1bad283f4cd04efa34d8a3d3651e27dca80af88
3
+ metadata.gz: faf10d33dce6efc9e10e62c0fcb8e8ab0e68f7be
4
+ data.tar.gz: 00b0e5a60ca0bc806e65d86bc3ede09dc8988c0d
5
5
  SHA512:
6
- metadata.gz: 4b0c682b1dfeed43223a616adae8ed7ec6847dc7099f515ea16d0e39f2c295879c652ef36a08e24f6704ca20559614bfb02ab4b04150af296ecd55990cc309b3
7
- data.tar.gz: fb9a994b4f8454279e9a3e21a3d0f3faac7cb6b74ffe0a6711b8ba063d5e0208ec2a24960240b33b17291ccc1ffbaadab2f05f71f6a2bff1c075129e9aba2a9c
6
+ metadata.gz: 600b56e3f0f6dcd2b9114b0f8a0e4ea66672415c5814b6d957beee91f3d642937529ab0d0bd3847ded91d646069cdd6995a9e1f6384a850f9cc35d84b0c889e1
7
+ data.tar.gz: efa23c535e3dc82e22c2e8249da2c6c848e0a8c006dc4126d92c76f92ce3d510ef567ed69198b2514caf2d2c87aef2345fe7877841370fa03d2119d664035d49
data/README.md CHANGED
@@ -70,6 +70,17 @@ the following into `lib/tasks/resque.rake`:
70
70
  end
71
71
  end
72
72
 
73
+
74
+ For normal work with fresh resque and resque-scheduler gems add next lines in lib/rake/resque.rake
75
+
76
+ ```ruby
77
+ task 'resque:pool:setup' do
78
+ Resque::Pool.after_prefork do |job|
79
+ Resque.redis.client.reconnect
80
+ end
81
+ end
82
+ ```
83
+
73
84
  ### Start the pool manager
74
85
 
75
86
  Then you can start the queues via:
data/lib/resque/pool.rb CHANGED
@@ -59,7 +59,7 @@ module Resque
59
59
  # Config: class methods to start up the pool using the default config {{{
60
60
 
61
61
  @config_files = ["resque-pool.yml", "config/resque-pool.yml"]
62
- class << self; attr_accessor :config_files, :app_name; end
62
+ class << self; attr_accessor :config_files, :app_name, :spawn_delay; end
63
63
 
64
64
  def self.app_name
65
65
  @app_name ||= File.basename(Dir.pwd)
@@ -215,17 +215,13 @@ module Resque
215
215
  when :INT
216
216
  graceful_worker_shutdown!(signal)
217
217
  when :TERM
218
- if term_child
218
+ case self.class.term_behavior
219
+ when "graceful_worker_shutdown_and_wait"
220
+ graceful_worker_shutdown_and_wait!(signal)
221
+ when "graceful_worker_shutdown"
219
222
  graceful_worker_shutdown!(signal)
220
223
  else
221
- case self.class.term_behavior
222
- when "graceful_worker_shutdown_and_wait"
223
- graceful_worker_shutdown_and_wait!(signal)
224
- when "graceful_worker_shutdown"
225
- graceful_worker_shutdown!(signal)
226
- else
227
- shutdown_everything_now!(signal)
228
- end
224
+ shutdown_everything_now!(signal)
229
225
  end
230
226
  end
231
227
  end
@@ -348,6 +344,7 @@ module Resque
348
344
  end
349
345
 
350
346
  def signal_all_workers(signal)
347
+ log "Sending #{signal} to all workers"
351
348
  all_pids.each do |pid|
352
349
  Process.kill signal, pid
353
350
  end
@@ -375,6 +372,7 @@ module Resque
375
372
  def spawn_missing_workers_for(queues)
376
373
  worker_delta_for(queues).times do |nr|
377
374
  spawn_worker!(queues)
375
+ sleep Resque::Pool.spawn_delay if Resque::Pool.spawn_delay
378
376
  end
379
377
  end
380
378
 
@@ -411,6 +409,10 @@ module Resque
411
409
  worker = ::Resque::Worker.new(*queues)
412
410
  worker.term_timeout = ENV['RESQUE_TERM_TIMEOUT'] || 4.0
413
411
  worker.term_child = ENV['TERM_CHILD']
412
+ if worker.respond_to?(:run_at_exit_hooks=)
413
+ # resque doesn't support this until 1.24, but we support 1.22
414
+ worker.run_at_exit_hooks = ENV['RUN_AT_EXIT_HOOKS'] || false
415
+ end
414
416
  if ENV['LOGGING'] || ENV['VERBOSE']
415
417
  worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
416
418
  end
@@ -1,10 +1,13 @@
1
1
  require 'trollop'
2
2
  require 'resque/pool'
3
+ require 'resque/pool/logging'
3
4
  require 'fileutils'
4
5
 
5
6
  module Resque
6
7
  class Pool
7
8
  module CLI
9
+ include Logging
10
+ extend Logging
8
11
  extend self
9
12
 
10
13
  def run
@@ -38,6 +41,7 @@ where [options] are:
38
41
  opt :nosync, "Don't sync logfiles on every write"
39
42
  opt :pidfile, "PID file location", :type => String, :short => "-p"
40
43
  opt :environment, "Set RAILS_ENV/RACK_ENV/RESQUE_ENV", :type => String, :short => "-E"
44
+ opt :spawn_delay, "Delay in milliseconds between spawning missing workers", :type => Integer, :short => "-s"
41
45
  opt :term_graceful_wait, "On TERM signal, wait for workers to shut down gracefully"
42
46
  opt :term_graceful, "On TERM signal, shut down workers gracefully"
43
47
  opt :term_immediate, "On TERM signal, shut down workers immediately (default)"
@@ -113,6 +117,15 @@ where [options] are:
113
117
  Resque::Pool.term_behavior = "graceful_worker_shutdown_and_wait"
114
118
  elsif opts[:term_graceful]
115
119
  Resque::Pool.term_behavior = "graceful_worker_shutdown"
120
+ elsif ENV["TERM_CHILD"]
121
+ log "TERM_CHILD enabled, so will user 'term-graceful-and-wait' behaviour"
122
+ Resque::Pool.term_behavior = "graceful_worker_shutdown_and_wait"
123
+ end
124
+ if ENV.include?("DYNO") && !ENV["TERM_CHILD"]
125
+ log "WARNING: Are you running on Heroku? You should probably set TERM_CHILD=1"
126
+ end
127
+ if opts[:spawn_delay]
128
+ Resque::Pool.spawn_delay = opts[:spawn_delay] * 0.001
116
129
  end
117
130
  end
118
131
 
@@ -2,14 +2,26 @@ require 'resque/worker'
2
2
 
3
3
  class Resque::Pool
4
4
  module PooledWorker
5
- def shutdown_with_pool
6
- shutdown_without_pool || Process.ppid == 1
5
+
6
+ def initialize_with_pool(*args)
7
+ @pool_master_pid = Process.pid
8
+ initialize_without_pool(*args)
9
+ end
10
+
11
+ def pool_master_has_gone_away?
12
+ @pool_master_pid && @pool_master_pid != Process.ppid
13
+ end
14
+
15
+ def shutdown_with_pool?
16
+ shutdown_without_pool? || pool_master_has_gone_away?
7
17
  end
8
18
 
9
19
  def self.included(base)
10
20
  base.instance_eval do
11
- alias_method :shutdown_without_pool, :shutdown?
12
- alias_method :shutdown?, :shutdown_with_pool
21
+ alias_method :initialize_without_pool, :initialize
22
+ alias_method :initialize, :initialize_with_pool
23
+ alias_method :shutdown_without_pool?, :shutdown?
24
+ alias_method :shutdown?, :shutdown_with_pool?
13
25
  end
14
26
  end
15
27
 
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  class Pool
3
- VERSION = "0.4.0.rc2"
3
+ VERSION = "0.4.0.rc3"
4
4
  end
5
5
  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.rc2
4
+ version: 0.4.0.rc3
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-09-25 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -136,27 +136,27 @@ files:
136
136
  - Rakefile
137
137
  - LICENSE.txt
138
138
  - Changelog.md
139
- - lib/resque/pool.rb
140
- - lib/resque/pool/tasks.rb
141
- - lib/resque/pool/pooled_worker.rb
142
139
  - lib/resque/pool/logging.rb
143
140
  - lib/resque/pool/cli.rb
144
141
  - lib/resque/pool/version.rb
142
+ - lib/resque/pool/tasks.rb
143
+ - lib/resque/pool/pooled_worker.rb
144
+ - lib/resque/pool.rb
145
145
  - bin/resque-pool
146
- - man/resque-pool.yml.5
146
+ - man/resque-pool.1.ronn
147
147
  - man/resque-pool.1
148
148
  - man/resque-pool.yml.5.ronn
149
- - man/resque-pool.1.ronn
149
+ - man/resque-pool.yml.5
150
150
  - features/basic_daemon_config.feature
151
151
  - features/support/aruba_daemon_support.rb
152
152
  - features/support/env.rb
153
- - features/step_definitions/resque-pool_steps.rb
154
153
  - features/step_definitions/daemon_steps.rb
155
- - spec/mock_config.rb
154
+ - features/step_definitions/resque-pool_steps.rb
156
155
  - spec/resque-pool.yml
157
- - spec/spec_helper.rb
158
- - spec/resque-pool-custom.yml.erb
156
+ - spec/mock_config.rb
159
157
  - spec/resque_pool_spec.rb
158
+ - spec/resque-pool-custom.yml.erb
159
+ - spec/spec_helper.rb
160
160
  homepage: http://github.com/nevans/resque-pool
161
161
  licenses:
162
162
  - MIT
@@ -177,17 +177,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: 1.3.1
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.0.3
180
+ rubygems_version: 2.0.14
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: quickly and easily fork a pool of resque workers
184
184
  test_files:
185
185
  - spec/mock_config.rb
186
- - spec/spec_helper.rb
187
186
  - spec/resque_pool_spec.rb
187
+ - spec/spec_helper.rb
188
188
  - spec/resque-pool.yml
189
189
  - features/support/aruba_daemon_support.rb
190
190
  - features/support/env.rb
191
- - features/step_definitions/resque-pool_steps.rb
192
191
  - features/step_definitions/daemon_steps.rb
192
+ - features/step_definitions/resque-pool_steps.rb
193
193
  - features/basic_daemon_config.feature
194
+ has_rdoc: