resqued 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -9
- data/lib/resqued/config/dsl.rb +1 -1
- data/lib/resqued/config/worker.rb +10 -11
- data/lib/resqued/listener.rb +3 -0
- data/lib/resqued/listener_proxy.rb +8 -6
- data/lib/resqued/master.rb +38 -7
- data/lib/resqued/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d66bf0dfa9299a44f871ae9835183600f6cc4e79
|
4
|
+
data.tar.gz: 318a6d0ec20aebbaf97260c3f2253394187ae2e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd97e21578a9cddaf82210459dc148790ed65ba92cd92c0d013764b03826df4683414ec1bfe56eeb73ebfe1bfe0854ba49826885a94c0c1ea38461e82a4affce
|
7
|
+
data.tar.gz: d8b4de064f53197605f7fc64bec9954a0bc8f4003bcd0c7334581043941e6e4762d42db0ee823a6c7ac085eaf6eb990be6d660b4dfd733bf877be09aa698ef5d
|
data/README.md
CHANGED
@@ -37,8 +37,8 @@ To run the same fleet of workers with resqued, create a config file
|
|
37
37
|
Another syntax for workers:
|
38
38
|
|
39
39
|
worker_pool 5
|
40
|
-
queue 'low',
|
41
|
-
queue 'normal',
|
40
|
+
queue 'low', :percent => 20
|
41
|
+
queue 'normal', :percent => 60
|
42
42
|
queue '*'
|
43
43
|
|
44
44
|
This time, you'd end up with something similar to this:
|
@@ -96,8 +96,9 @@ You can configure the Resque worker in the `after_fork` block
|
|
96
96
|
worker 'low', :interval => 30
|
97
97
|
|
98
98
|
worker_pool 5, :interval => 1
|
99
|
-
queue '
|
100
|
-
queue '
|
99
|
+
queue 'high', 'almosthigh'
|
100
|
+
queue 'low', :percent => 20
|
101
|
+
queue 'normal', :count => 4
|
101
102
|
queue '*'
|
102
103
|
|
103
104
|
before_fork do
|
@@ -114,11 +115,11 @@ You can configure the Resque worker in the `after_fork` block
|
|
114
115
|
In this example, a Rails application is being set up with 7 workers:
|
115
116
|
* high
|
116
117
|
* low (interval = 30)
|
117
|
-
* low, normal, * (interval = 1)
|
118
|
-
* normal, * (interval = 1)
|
119
|
-
* normal, * (interval = 1)
|
120
|
-
* normal, * (interval = 1)
|
121
|
-
* * (interval = 1)
|
118
|
+
* high, almosthigh, low, normal, * (interval = 1)
|
119
|
+
* high, almosthigh, normal, * (interval = 1)
|
120
|
+
* high, almosthigh, normal, * (interval = 1)
|
121
|
+
* high, almosthigh, normal, * (interval = 1)
|
122
|
+
* high, almosthigh, * (interval = 1)
|
122
123
|
|
123
124
|
## Multiple configurations
|
124
125
|
|
data/lib/resqued/config/dsl.rb
CHANGED
@@ -40,25 +40,24 @@ module Resqued
|
|
40
40
|
#
|
41
41
|
# queue 'one'
|
42
42
|
# queue '*'
|
43
|
-
# queue '
|
44
|
-
# queue 'three', 5
|
45
|
-
# queue 'four', :percent => 10
|
43
|
+
# queue 'four-a', 'four-b', :percent => 10
|
46
44
|
# queue 'five', :count => 5
|
47
|
-
def queue(
|
48
|
-
|
49
|
-
|
45
|
+
def queue(*queues)
|
46
|
+
options = queues.last.is_a?(Hash) ? queues.pop : {}
|
47
|
+
concurrency =
|
48
|
+
case options
|
50
49
|
when Hash
|
51
|
-
if percent =
|
50
|
+
if percent = options[:percent]
|
52
51
|
percent * 0.01
|
53
|
-
elsif count =
|
52
|
+
elsif count = options[:count]
|
54
53
|
count
|
55
54
|
else
|
56
55
|
1.0
|
57
56
|
end
|
58
|
-
|
59
|
-
|
60
|
-
else concurrency.to_i
|
57
|
+
else
|
58
|
+
1.0
|
61
59
|
end
|
60
|
+
queues.each { |queue| @pool_queues[queue] = concurrency }
|
62
61
|
end
|
63
62
|
|
64
63
|
private
|
data/lib/resqued/listener.rb
CHANGED
@@ -4,6 +4,7 @@ require 'resqued/config'
|
|
4
4
|
require 'resqued/logging'
|
5
5
|
require 'resqued/procline_version'
|
6
6
|
require 'resqued/sleepy'
|
7
|
+
require 'resqued/version'
|
7
8
|
require 'resqued/worker'
|
8
9
|
|
9
10
|
module Resqued
|
@@ -32,6 +33,7 @@ module Resqued
|
|
32
33
|
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
|
33
34
|
ENV['RESQUED_STATE'] = (@running_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
|
34
35
|
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
|
36
|
+
ENV['RESQUED_MASTER_VERSION'] = Resqued::VERSION
|
35
37
|
log "exec: #{Resqued::START_CTX['$0']} listener"
|
36
38
|
Kernel.exec(Resqued::START_CTX['$0'], 'listener', socket_fd => socket_fd) # The hash at the end only works in new-ish (1.9+ or so) rubies. It's required for ruby 2.0.
|
37
39
|
end
|
@@ -67,6 +69,7 @@ module Resqued
|
|
67
69
|
|
68
70
|
config = Resqued::Config.new(@config_paths)
|
69
71
|
config.before_fork
|
72
|
+
report_to_master("RUNNING")
|
70
73
|
|
71
74
|
write_procline('running')
|
72
75
|
init_workers(config)
|
@@ -67,16 +67,18 @@ module Resqued
|
|
67
67
|
|
68
68
|
# Public: Check for updates on running worker information.
|
69
69
|
def read_worker_status(options)
|
70
|
-
|
70
|
+
on_activity = options[:on_activity]
|
71
71
|
until @master_socket.nil?
|
72
72
|
IO.select([@master_socket], nil, nil, 0) or return
|
73
|
-
line = @master_socket.readline
|
74
|
-
|
73
|
+
case line = @master_socket.readline
|
74
|
+
when /^\+(\d+),(.*)$/
|
75
75
|
worker_pids[$1] = $2
|
76
|
-
|
76
|
+
when /^-(\d+)$/
|
77
77
|
worker_pids.delete($1)
|
78
|
-
|
79
|
-
|
78
|
+
on_activity.worker_finished($1) if on_activity
|
79
|
+
when /^RUNNING/
|
80
|
+
on_activity.listener_running(self) if on_activity
|
81
|
+
when ''
|
80
82
|
break
|
81
83
|
else
|
82
84
|
log "Malformed data from listener: #{line.inspect}"
|
data/lib/resqued/master.rb
CHANGED
@@ -52,11 +52,12 @@ module Resqued
|
|
52
52
|
when :HUP
|
53
53
|
reopen_logs
|
54
54
|
log "Restarting listener with new configuration and application."
|
55
|
-
|
55
|
+
prepare_new_listener
|
56
56
|
when :USR2
|
57
57
|
log "Pause job processing"
|
58
58
|
@paused = true
|
59
|
-
kill_listener(:QUIT)
|
59
|
+
kill_listener(:QUIT, @current_listener)
|
60
|
+
@current_listener = nil
|
60
61
|
when :CONT
|
61
62
|
log "Resume job processing"
|
62
63
|
@paused = false
|
@@ -122,23 +123,53 @@ module Resqued
|
|
122
123
|
|
123
124
|
def read_listeners
|
124
125
|
all_listeners.each do |l|
|
125
|
-
l.read_worker_status(:
|
126
|
+
l.read_worker_status(:on_activity => self)
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
130
|
+
# Listener message: A worker just stopped working.
|
131
|
+
#
|
132
|
+
# Forwards the message to the other listeners.
|
129
133
|
def worker_finished(pid)
|
130
134
|
all_listeners.each do |other|
|
131
135
|
other.worker_finished(pid)
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
+
# Listener message: A listener finished booting, and is ready to start workers.
|
140
|
+
#
|
141
|
+
# Promotes a booting listener to be the current listener.
|
142
|
+
def listener_running(listener)
|
143
|
+
if listener == @current_listener
|
144
|
+
kill_listener(:QUIT, @last_good_listener)
|
145
|
+
@last_good_listener = nil
|
146
|
+
else
|
147
|
+
# This listener didn't receive the last SIGQUIT we sent.
|
148
|
+
# (It was probably sent before the listener had set up its traps.)
|
149
|
+
# So kill it again. We have moved on.
|
150
|
+
kill_listener(:QUIT, listener)
|
139
151
|
end
|
140
152
|
end
|
141
153
|
|
154
|
+
# Private: Spin up a new listener.
|
155
|
+
#
|
156
|
+
# The old one will be killed when the new one is ready for workers.
|
157
|
+
def prepare_new_listener
|
158
|
+
if @last_good_listener
|
159
|
+
# The last_good_listener is still running because we got another HUP before the new listener finished booting.
|
160
|
+
# Keep the last_good_listener (where all the workers are) and kill the booting current_listener. We'll start a new one.
|
161
|
+
kill_listener(:QUIT, @current_listener)
|
162
|
+
else
|
163
|
+
@last_good_listener = @current_listener
|
164
|
+
end
|
165
|
+
# Indicate to `start_listener` that it should start a new listener.
|
166
|
+
@current_listener = nil
|
167
|
+
end
|
168
|
+
|
169
|
+
def kill_listener(signal, listener)
|
170
|
+
listener.kill(signal) if listener
|
171
|
+
end
|
172
|
+
|
142
173
|
def kill_all_listeners(signal)
|
143
174
|
all_listeners.each do |l|
|
144
175
|
l.kill(signal)
|
data/lib/resqued/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resqued
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Burke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kgio
|