resque-sliders 0.2.1 → 0.2.2
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.
@@ -10,12 +10,17 @@ module Resque
|
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@host_status = redis_get_hash(host_config_key)
|
13
|
-
@stale_hosts = Resque.redis.
|
13
|
+
@stale_hosts = Resque.redis.smembers(known_hosts_key) - hosts
|
14
14
|
end
|
15
15
|
|
16
16
|
# Return Array of currently online hosts
|
17
17
|
def hosts
|
18
|
-
|
18
|
+
Set.new.tap do |l|
|
19
|
+
@host_status.keys.each do |x|
|
20
|
+
x = x.split(':')
|
21
|
+
l << x.first unless %w(reload pause stop).include?(x.last)
|
22
|
+
end
|
23
|
+
end.to_a.sort
|
19
24
|
end
|
20
25
|
|
21
26
|
# Array of all hosts (current + stale)
|
@@ -23,6 +28,18 @@ module Resque
|
|
23
28
|
(hosts + stale_hosts).sort
|
24
29
|
end
|
25
30
|
|
31
|
+
# Remove all keys for a host (clean)
|
32
|
+
def remove_all_host_keys(hostname)
|
33
|
+
# expensive process O(N)
|
34
|
+
keys_to_delete = Resque.redis.keys("#{key_prefix}:*").select { |k| name = k.split(':').last; hostname == name }
|
35
|
+
# look at config hash, remove fields if relate to this hostname
|
36
|
+
fields_to_delete = redis_get_hash(host_config_key).keys.select { |k| name = k.split(':').first; hostname == name }
|
37
|
+
# do delete
|
38
|
+
Resque.redis.del(keys_to_delete) unless keys_to_delete.empty?
|
39
|
+
redis_del_hash(host_config_key, fields_to_delete) unless fields_to_delete.empty?
|
40
|
+
del_from_known_hosts(hostname)
|
41
|
+
end
|
42
|
+
|
26
43
|
# Return current children count or nil if Host hasn't registered itself.
|
27
44
|
def current_children(host)
|
28
45
|
@host_status["#{host}:current_children"].to_i if max_children(host)
|
@@ -3,12 +3,28 @@ module Resque
|
|
3
3
|
module ResqueSliders
|
4
4
|
module Helpers
|
5
5
|
|
6
|
+
# prefix to all keys our plugin uses in redis
|
6
7
|
def key_prefix
|
7
8
|
"plugins:resque-sliders"
|
8
9
|
end
|
9
10
|
|
11
|
+
# we store everything in this hash
|
10
12
|
def host_config_key
|
11
|
-
"
|
13
|
+
"#{key_prefix}:host_configs"
|
14
|
+
end
|
15
|
+
|
16
|
+
# used to keep track of hosts we know about
|
17
|
+
def known_hosts_key
|
18
|
+
"#{key_prefix}:known_hosts"
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_to_known_hosts(hostname)
|
22
|
+
# add a hostname to the hosts set
|
23
|
+
Resque.redis.sadd(known_hosts_key, hostname)
|
24
|
+
end
|
25
|
+
|
26
|
+
def del_from_known_hosts(hostname)
|
27
|
+
Resque.redis.srem(known_hosts_key, hostname)
|
12
28
|
end
|
13
29
|
|
14
30
|
def redis_get_hash(key)
|
@@ -163,6 +163,7 @@ module Resque
|
|
163
163
|
register_signal_handlers
|
164
164
|
clean_signal_settings
|
165
165
|
register_setting('max_children', @max_children)
|
166
|
+
add_to_known_hosts(@hostname)
|
166
167
|
log! "Registered Max Children with Redis"
|
167
168
|
$stdout.sync = true
|
168
169
|
end
|
@@ -361,12 +362,10 @@ module Resque
|
|
361
362
|
# Issue wait() to make sure pid isn't forgotten
|
362
363
|
Timeout::timeout(wait) { Process.wait(pid) }
|
363
364
|
to_delete << pid
|
364
|
-
next
|
365
365
|
rescue Timeout::Error
|
366
366
|
# waited too long so just catch and ignore, and continue
|
367
367
|
rescue Errno::ESRCH, Errno::ECHILD # child is gone
|
368
368
|
to_delete << pid
|
369
|
-
next
|
370
369
|
end
|
371
370
|
end
|
372
371
|
to_delete.each { |pid| @zombie_pids.delete(pid) }
|
@@ -45,6 +45,11 @@ module Resque
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
# we need the ability to remove old hosts
|
49
|
+
app.delete '/sliders/:host' do
|
50
|
+
Commander.new.remove_all_host_keys(params[:host])
|
51
|
+
end
|
52
|
+
|
48
53
|
app.helpers do
|
49
54
|
def slider_view(filename, options={}, locals={})
|
50
55
|
erb(File.read(File.join(VIEW_PATH, "#{filename}.erb")), options, locals)
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-sliders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.1
|
5
4
|
prerelease:
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Mullin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
16
|
+
type: :runtime
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
@@ -22,10 +22,8 @@ dependencies:
|
|
22
22
|
- - <
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: '2.0'
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
27
|
requirements:
|
30
28
|
- - ! '>='
|
31
29
|
- !ruby/object:Gem::Version
|
@@ -33,6 +31,8 @@ dependencies:
|
|
33
31
|
- - <
|
34
32
|
- !ruby/object:Gem::Version
|
35
33
|
version: '2.0'
|
34
|
+
none: false
|
35
|
+
prerelease: false
|
36
36
|
description: ! " Resque-Sliders is a plugin for Resque that enables you to control
|
37
37
|
multiple hosts'\n running resque workers with a monitor PID watching over them.
|
38
38
|
\ From the resque-web UI, you\n can add/delete/change which queues are running
|
@@ -83,26 +83,26 @@ rdoc_options: []
|
|
83
83
|
require_paths:
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
86
|
requirements:
|
88
87
|
- - ! '>='
|
89
88
|
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
89
|
segments:
|
92
90
|
- 0
|
93
|
-
hash:
|
94
|
-
|
91
|
+
hash: -2979142470906782605
|
92
|
+
version: '0'
|
95
93
|
none: false
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
95
|
requirements:
|
97
96
|
- - ! '>='
|
98
97
|
- !ruby/object:Gem::Version
|
99
|
-
version: '0'
|
100
98
|
segments:
|
101
99
|
- 0
|
102
|
-
hash:
|
100
|
+
hash: -2979142470906782605
|
101
|
+
version: '0'
|
102
|
+
none: false
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.25
|
106
106
|
signing_key:
|
107
107
|
specification_version: 3
|
108
108
|
summary: ! 'Resque-Sliders: a plugin for resque that controls which resque workers
|