resque-pool 0.4.0 → 0.5.0.rc1

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: e53fe4edb6e3714b9290bb7c5aaa38cfc0cba522
4
- data.tar.gz: 14d005755bff347031cb00eca84a32cfe0745e74
3
+ metadata.gz: d1fd139240f241bd110b1b3f80a6812bd088ab5e
4
+ data.tar.gz: 5e2835129794d3701e28e05372092d4ffc66843b
5
5
  SHA512:
6
- metadata.gz: 70c830c5077481580b4dfc228f65607e1af4f8a8577a4993965820a4422e96422391df3fa65264e60f9f16169a9279bab231b7fac5c30ec0c06e65874564b334
7
- data.tar.gz: da6496b4c8174cd7196a0175e4fe6abe111337b0ff99a442b1e82eb68a869924352298ad55b8a8855bb50a563703422d0d1aac24da82b937a3b64da4336c69f5
6
+ metadata.gz: 4ac62b6fb33e095ed8b05b54be9e2b5377c2c92976335301ad8067fb1cf9ebe8a671c771760d4c91c7a93aebe63823f75fe144c840b43460183034aa4072f77c
7
+ data.tar.gz: dca7e927e99936b87cfbd9d714ee9eabe5bda548d2cb0261c757e26cb5db6b05ff661ca136da9d87bf493fd00408789863e5f60de1da63e3322fd0af8d3425da
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
 
@@ -397,6 +395,7 @@ module Resque
397
395
  worker = create_worker(queues)
398
396
  pid = fork do
399
397
  Process.setpgrp unless Resque::Pool.single_process_group
398
+ worker.worker_parent_pid = Process.pid
400
399
  log_worker "Starting worker #{worker}"
401
400
  call_after_prefork!
402
401
  reset_sig_handlers!
@@ -409,8 +408,13 @@ module Resque
409
408
  def create_worker(queues)
410
409
  queues = queues.to_s.split(',')
411
410
  worker = ::Resque::Worker.new(*queues)
411
+ worker.pool_master_pid = Process.pid
412
412
  worker.term_timeout = ENV['RESQUE_TERM_TIMEOUT'] || 4.0
413
413
  worker.term_child = ENV['TERM_CHILD']
414
+ if worker.respond_to?(:run_at_exit_hooks=)
415
+ # resque doesn't support this until 1.24, but we support 1.22
416
+ worker.run_at_exit_hooks = ENV['RUN_AT_EXIT_HOOKS'] || false
417
+ end
414
418
  if ENV['LOGGING'] || ENV['VERBOSE']
415
419
  worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
416
420
  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,30 @@ 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
+ attr_accessor :pool_master_pid
6
+ attr_accessor :worker_parent_pid
7
+
8
+ # We can't just check if we've been re-parented to PID 1 (init) because we
9
+ # want to support docker (which will make the pool master PID 1).
10
+ #
11
+ # We also check the worker_parent_pid, because resque-multi-jobs-fork calls
12
+ # Worker#shutdown? from inside the worker child process.
13
+ def pool_master_has_gone_away?
14
+ not potential_parent_pids.include?(Process.ppid)
15
+ end
16
+
17
+ def potential_parent_pids
18
+ [pool_master_pid, worker_parent_pid].compact
19
+ end
20
+
21
+ def shutdown_with_pool?
22
+ shutdown_without_pool? || pool_master_has_gone_away?
7
23
  end
8
24
 
9
25
  def self.included(base)
10
26
  base.instance_eval do
11
- alias_method :shutdown_without_pool, :shutdown?
12
- alias_method :shutdown?, :shutdown_with_pool
27
+ alias_method :shutdown_without_pool?, :shutdown?
28
+ alias_method :shutdown?, :shutdown_with_pool?
13
29
  end
14
30
  end
15
31
 
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  class Pool
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0.rc1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nicholas a. evans
@@ -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
@@ -172,9 +172,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - '>'
176
176
  - !ruby/object:Gem::Version
177
- version: '0'
177
+ version: 1.3.1
178
178
  requirements: []
179
179
  rubyforge_project:
180
180
  rubygems_version: 2.0.14