resque-sliders 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -47,13 +47,17 @@ Options:
47
47
  -p, --pidfile PIDFILE PID File location
48
48
  -f, --force FORCE KILL ANY OTHER RUNNING KEWATCHERS
49
49
  -v, --verbose Verbosity (Can be specified more than once, -vv)
50
- -m, --max MAX Max Children
50
+ -m, --max MAX Max Children (default: 10)
51
+ -t, --time TIME Total Time (in minutes) to wait for ALL Workers to die before having them force killed (default: 2 minutes)
52
+ -w, --wait WAIT_TIME Minimum Time (in seconds) to wait for individual Worker to die at a time (default: 25 seconds)
51
53
  -h, --help This help
52
54
  ```
53
55
 
54
56
  **Important Options**
55
57
 
56
58
  * `Max Children (-m|--max MAX)`: Maximum number of workers to run on host (default: 10)
59
+ * `Total Time (-t|--time TIME)`: How long you want to wait before sending `TERM` to resque (like `kill -9`) (default: 2 minutes)
60
+ * `Wait Time (-w|--wait WAIT_TIME)`: How many seconds **MINIMUM** we spend in blocking wait() call per worker when cleaning up zombies (default: 25 seconds)
57
61
  * `Rakefile (-r|--rakefile RAKEFILE)`: Pass along a rakefile to use when calling `rake ... resque:work` - shouldn't be needed if run from project directory
58
62
  * `Force (-f|--force)`: Force any currently running KEWatcher processes to QUIT, waiting for it to do so, and starting in its place
59
63
  * `RAILS_ENV`: If you're using rails, you need to set your RAILS_ENV variable
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
- require 'bundler/gem_tasks'
2
- require 'resque/tasks'
1
+ $LOAD_PATH.unshift 'helpers'
2
+ $LOAD_PATH.unshift 'lib'
3
3
  #
4
4
  # Setup
5
5
  #
6
6
 
7
- $LOAD_PATH.unshift 'lib'
7
+
8
+ require 'bundler/gem_tasks'
9
+ require 'resque/tasks'
10
+ require 'resque_job'
8
11
 
9
12
  def command?(command)
10
13
  system("type #{command} > /dev/null 2>&1")
data/bin/kewatcher CHANGED
@@ -35,14 +35,22 @@ OptionParser.new do |opt|
35
35
  options[:force] = true
36
36
  end
37
37
 
38
- opt.on("-v", "--verbose", "Verbosity") do
38
+ opt.on("-v", "--verbose", "Verbosity (Can be specified more than once, -vv)") do
39
39
  options[:verbosity] += 1
40
40
  end
41
41
 
42
- opt.on("-m", "--max MAX", "Max Children") do |max|
42
+ opt.on("-m", "--max MAX", "Max Children (default: 10)") do |max|
43
43
  options[:max_children] = max.to_i
44
44
  end
45
45
 
46
+ opt.on("-t", "--time TIME", "Total Time (in minutes) to wait for ALL Workers to die before having them force killed (default: 2 minutes)") do |ttime|
47
+ options[:ttime] = ttime.to_f
48
+ end
49
+
50
+ opt.on("-w", "--wait WAIT_TIME", "Minimum Time (in seconds) to wait for individual Worker to die at a time (default: 25 seconds)") do |wait|
51
+ options[:wait] = wait.to_f
52
+ end
53
+
46
54
  opt.on("-h", "--help", "This help") do
47
55
  puts opt
48
56
  exit
@@ -17,6 +17,8 @@ module Resque
17
17
  # Initialize daemon with options from command-line.
18
18
  def initialize(options={})
19
19
  @verbosity = (options[:verbosity] || 0).to_i
20
+ @ttime = options[:ttime] || 2
21
+ @zombie_wait = options[:wait] || 30
20
22
  @hostile_takeover = options[:force]
21
23
  @rakefile = File.expand_path(options[:rakefile]) rescue nil
22
24
  @rakefile = File.exists?(@rakefile) ? @rakefile : nil if @rakefile
@@ -29,7 +31,7 @@ module Resque
29
31
  @pids = Hash.new # init pids array to track running children
30
32
  @need_queues = Array.new # keep track of pids that are needed
31
33
  @dead_queues = Array.new # keep track of pids that are dead
32
- @zombie_pids = Array.new # keep track of zombie's we kill and dont watch()
34
+ @zombie_pids = Hash.new # keep track of zombie's we kill and dont watch(), with elapsed time we've waited for it to die
33
35
 
34
36
  Resque.redis = case options[:config]
35
37
  when Hash
@@ -74,7 +76,7 @@ module Resque
74
76
  procline if tick
75
77
 
76
78
  sleep(interval) # microsleep
77
- kill_zombies! # need to cleanup ones we've killed
79
+ kill_zombies! unless shutdown? # need to cleanup ones we've killed
78
80
 
79
81
  @pids.keys.each do |pid|
80
82
  begin
@@ -289,14 +291,36 @@ module Resque
289
291
  end
290
292
 
291
293
  def kill_zombies!
292
- @zombie_pids.dup.each do |pid|
294
+ return if @zombie_pids.empty?
295
+ zombies = @zombie_pids.dup
296
+ wait = 60 * @ttime / zombies.length # in seconds
297
+ mark = Time.now # start of loop
298
+ zombies.each do |pid,elapsed|
299
+ elapsed += Time.now - mark
300
+ mark = Time.now # mark that we updated elapsed; time becomes relative
301
+ time_left = (@ttime * 60.0) - elapsed # seconds
302
+ wait = time_left < wait ? time_left : wait
303
+ wait = @zombie_wait if wait < @zombie_wait && wait > 0
304
+ wait = 0.1 if wait <= 0
305
+ log! "Waiting for Zombie: #{pid} (#{'%.2f' % wait} seconds) => #{'%.2f' % elapsed} elapsed"
293
306
  begin
294
- log! "Waiting for Zombie: #{pid}"
295
307
  # Issue wait() to make sure pid isn't forgotten
296
- Process.wait(@zombie_pids.pop)
297
- rescue Errno::ECHILD
308
+ Timeout::timeout(wait) { Process.wait(pid) }
309
+ rescue Timeout::Error
310
+ elapsed += Time.now - mark
311
+ mark = Time.now # mark that we updated elapsed
312
+ log! "TIMEOUT waiting for zombie #{pid} => #{'%.2f' % elapsed} elapsed"
313
+ (log "Waited more than #{@ttime} minutes for #{pid}. Force quitting..."; Process.kill('TERM',pid)) if elapsed / 60.0 >= @ttime
298
314
  next
315
+ rescue Errno::ECHILD # child is gone
316
+ ensure
317
+ elapsed += Time.now - mark
318
+ mark = Time.now # mark that we updated elapsed
319
+ log! "Elapsed incr: #{elapsed}"
320
+ zombies.each_key { |x| zombies[x] = elapsed } # reset all to current elapsed
321
+ @zombie_pids = zombies # make sure to update root Hash
299
322
  end
323
+ @zombie_pids.delete(pid)
300
324
  end
301
325
  end
302
326
 
@@ -308,7 +332,7 @@ module Resque
308
332
  log! "Child #{pid} already dead, sad day. (#{@pids.keys.length-1}) #{e}"
309
333
  ensure
310
334
  # Keep track of ones we issued QUIT to
311
- @zombie_pids << pid
335
+ @zombie_pids[pid] = 0 # set to 0 wait time
312
336
  end
313
337
  end
314
338
 
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module ResqueSliders
4
- Version = VERSION = '0.0.10'
4
+ Version = VERSION = '0.0.11'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,48 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque-sliders
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 10
10
- version: 0.0.10
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kevin Mullin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-08 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: resque
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2156319820 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 43
29
- segments:
30
- - 1
31
- - 15
32
- - 0
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.15.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- description: " Resque-Sliders is a plugin for Resque that enables you to control multiple hosts'\n running resque workers with a monitor PID watching over them. From the resque-web UI, you\n can add/delete/change which queues are running on each host running the monitor PID.\n Sliders are in the UI and allow you to adjust how many workers on either host should be running.\n"
23
+ prerelease: false
24
+ version_requirements: *2156319820
25
+ description: ! " Resque-Sliders is a plugin for Resque that enables you to control
26
+ multiple hosts'\n running resque workers with a monitor PID watching over them.
27
+ \ From the resque-web UI, you\n can add/delete/change which queues are running
28
+ on each host running the monitor PID.\n Sliders are in the UI and allow you to
29
+ adjust how many workers on either host should be running.\n"
37
30
  email: kevin@kpmullin.com
38
- executables:
31
+ executables:
39
32
  - kewatcher
40
33
  extensions: []
41
-
42
- extra_rdoc_files:
34
+ extra_rdoc_files:
43
35
  - README.md
44
36
  - MIT-LICENSE
45
- files:
37
+ files:
46
38
  - Gemfile
47
39
  - MIT-LICENSE
48
40
  - README.md
@@ -78,38 +70,30 @@ files:
78
70
  - test/test_helper.rb
79
71
  homepage: https://github.com/kmullin/resque-sliders
80
72
  licenses: []
81
-
82
73
  post_install_message:
83
74
  rdoc_options: []
84
-
85
- require_paths:
75
+ require_paths:
86
76
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
88
78
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
84
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
105
89
  requirements: []
106
-
107
90
  rubyforge_project:
108
91
  rubygems_version: 1.8.15
109
92
  signing_key:
110
93
  specification_version: 3
111
- summary: "Resque-Sliders: a plugin for resque that controls which resque workers are running on each host, from within Resque-web"
112
- test_files:
94
+ summary: ! 'Resque-Sliders: a plugin for resque that controls which resque workers
95
+ are running on each host, from within Resque-web'
96
+ test_files:
113
97
  - test/redis-test.conf
114
98
  - test/resque-sliders_test.rb
115
99
  - test/test_helper.rb