resqued 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +7 -0
- data/exe/resqued +23 -8
- data/lib/resqued/config/base.rb +8 -0
- data/lib/resqued/config/dsl.rb +1 -1
- data/lib/resqued/config/worker.rb +8 -4
- data/lib/resqued/config.rb +8 -9
- data/lib/resqued/listener.rb +10 -7
- data/lib/resqued/master.rb +3 -6
- data/lib/resqued/version.rb +1 -2
- data/lib/resqued/worker.rb +2 -2
- metadata +15 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e5a83c5ce92209fd4dc917cb9b85a145206047a
|
4
|
+
data.tar.gz: de4d9dabfe0a6f37e8b973faa0d436cde0618c90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2bdc8dd96addce81a01ea4248c1471d75ed803142edfd32f166cb2e2d4a7683b08b848ea4bd513e3520a981d8dee6cd44f73a0cdacf3310336919b02e6ae07f
|
7
|
+
data.tar.gz: 4945877eb7e3c0312996d43cd447f271966d0cc97fefca9ef5ed8019d3cc587fb3ab1f8090326655be30550ff76745aca46ca682ddc65b91963ff5fd3f6d5d01
|
data/README.md
CHANGED
@@ -120,6 +120,13 @@ In this example, a Rails application is being set up with 7 workers:
|
|
120
120
|
* normal, * (interval = 1)
|
121
121
|
* * (interval = 1)
|
122
122
|
|
123
|
+
## Multiple configurations
|
124
|
+
|
125
|
+
If your app has several work machines, each with the same application code but different sets of workers, you might want to have a shared config file for the `before_fork` and `after_fork` blocks. You can pass in several config files, and resqued will act as if you concatenated them.
|
126
|
+
|
127
|
+
$ resqued config/shared.rb config/pool-a.rb
|
128
|
+
$ resqued config/shared.rb config/pool-b.rb
|
129
|
+
|
123
130
|
## See also
|
124
131
|
|
125
132
|
For information about how resqued works, see the [documentation](docs/).
|
data/exe/resqued
CHANGED
@@ -4,9 +4,10 @@ require 'optparse'
|
|
4
4
|
|
5
5
|
options = {}
|
6
6
|
daemonize = false
|
7
|
+
test = false
|
7
8
|
|
8
9
|
opts = OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: resqued [options] resqued-config-
|
10
|
+
opts.banner = "Usage: resqued [options] resqued-config-files..."
|
10
11
|
|
11
12
|
opts.on '-h', '--help', 'Show this message' do
|
12
13
|
puts opts
|
@@ -19,6 +20,10 @@ opts = OptionParser.new do |opts|
|
|
19
20
|
exit
|
20
21
|
end
|
21
22
|
|
23
|
+
opts.on '--test', 'Report which worker would start' do
|
24
|
+
test = true
|
25
|
+
end
|
26
|
+
|
22
27
|
opts.on '-p', '--pidfile PIDFILE', 'Store the pid of the master process in PIDFILE' do |v|
|
23
28
|
options[:master_pidfile] = v
|
24
29
|
end
|
@@ -34,16 +39,26 @@ opts = OptionParser.new do |opts|
|
|
34
39
|
end
|
35
40
|
|
36
41
|
opts.parse!
|
42
|
+
options[:config_paths] = ARGV
|
37
43
|
|
38
|
-
|
44
|
+
if options[:config_paths].size == 0
|
39
45
|
puts opts
|
40
46
|
exit 1
|
41
47
|
end
|
42
48
|
|
43
|
-
|
44
|
-
resqued
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
if test
|
50
|
+
require 'resqued/config'
|
51
|
+
workers = Resqued::Config.new(options[:config_paths]).build_workers
|
52
|
+
puts "Workers defined in #{options[:config_paths].join(' ')}"
|
53
|
+
workers.each_with_index do |worker, index|
|
54
|
+
puts "#{index + 1}: #{worker.queues.join(',')}"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
require 'resqued/master'
|
58
|
+
resqued = Resqued::Master.new(options)
|
59
|
+
if daemonize
|
60
|
+
require 'resqued/daemon'
|
61
|
+
resqued = Resqued::Daemon.new(resqued)
|
62
|
+
end
|
63
|
+
resqued.run
|
48
64
|
end
|
49
|
-
resqued.run
|
data/lib/resqued/config/base.rb
CHANGED
@@ -15,6 +15,14 @@ module Resqued
|
|
15
15
|
results
|
16
16
|
end
|
17
17
|
|
18
|
+
# Public: Apply the configuration from several files.
|
19
|
+
def apply_all(configs)
|
20
|
+
configs.each do |config|
|
21
|
+
instance_eval(config[:content], config[:path])
|
22
|
+
end
|
23
|
+
results
|
24
|
+
end
|
25
|
+
|
18
26
|
private
|
19
27
|
|
20
28
|
# Private: The results of applying the config.
|
data/lib/resqued/config/dsl.rb
CHANGED
@@ -17,7 +17,7 @@ module Resqued
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Public: Define a pool of workers that will work '*', or the queues specified by `queue`.
|
20
|
-
def worker_pool(count,
|
20
|
+
def worker_pool(count, *queues_and_options)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Public: Define the queues worked by members of the worker pool.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'resqued/config/base'
|
2
|
+
require 'resqued/worker'
|
2
3
|
|
3
4
|
module Resqued
|
4
5
|
module Config
|
@@ -18,18 +19,21 @@ module Resqued
|
|
18
19
|
#
|
19
20
|
# worker 'one', :interval => 1
|
20
21
|
def worker(*queues)
|
21
|
-
options = queues.last.is_a?(Hash) ? queues.pop : {}
|
22
|
+
options = queues.last.is_a?(Hash) ? queues.pop.dup : {}
|
23
|
+
queues = queues.flatten
|
22
24
|
queues = ['*'] if queues.empty?
|
23
|
-
|
25
|
+
queues = queues.shuffle if options.delete(:shuffle_queues)
|
26
|
+
@workers << @worker_class.new(options.merge(@worker_options).merge(:queues => queues))
|
24
27
|
end
|
25
28
|
|
26
29
|
# DSL: Set up a pool of workers. Define queues for the members of the pool with `queue`.
|
27
30
|
#
|
28
31
|
# worker_pool 20, :interval => 1
|
29
|
-
def worker_pool(count,
|
32
|
+
def worker_pool(count, *queues)
|
30
33
|
@pool_size = count
|
31
|
-
@pool_options =
|
34
|
+
@pool_options = queues.last.is_a?(Hash) ? queues.pop : {}
|
32
35
|
@pool_queues = {}
|
36
|
+
queues.each { |q| queue q }
|
33
37
|
end
|
34
38
|
|
35
39
|
# DSL: Define a queue for the worker_pool to work from.
|
data/lib/resqued/config.rb
CHANGED
@@ -7,30 +7,29 @@ module Resqued
|
|
7
7
|
# Public: Build a new ConfigFile instance.
|
8
8
|
#
|
9
9
|
# Resqued::Config is a module because the evaluators say so, so this `new` is a factory for another class.
|
10
|
-
def self.new(
|
11
|
-
|
10
|
+
def self.new(paths)
|
11
|
+
Configuration.new(paths)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Does the things that the config file says to do.
|
15
|
-
class
|
16
|
-
def initialize(
|
17
|
-
@
|
18
|
-
@contents = File.read(@path)
|
15
|
+
class Configuration
|
16
|
+
def initialize(config_paths)
|
17
|
+
@config_data = config_paths.map { |path| {:content => File.read(path), :path => path} }
|
19
18
|
end
|
20
19
|
|
21
20
|
# Public: Performs the `before_fork` action from the config.
|
22
21
|
def before_fork
|
23
|
-
Resqued::Config::BeforeFork.new.
|
22
|
+
Resqued::Config::BeforeFork.new.apply_all(@config_data)
|
24
23
|
end
|
25
24
|
|
26
25
|
# Public: Performs the `after_fork` action from the config.
|
27
26
|
def after_fork(worker)
|
28
|
-
Resqued::Config::AfterFork.new(:worker => worker).
|
27
|
+
Resqued::Config::AfterFork.new(:worker => worker).apply_all(@config_data)
|
29
28
|
end
|
30
29
|
|
31
30
|
# Public: Builds the workers specified in the config.
|
32
31
|
def build_workers
|
33
|
-
Resqued::Config::Worker.new(:config => self).
|
32
|
+
Resqued::Config::Worker.new(:config => self).apply_all(@config_data)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
data/lib/resqued/listener.rb
CHANGED
@@ -15,7 +15,7 @@ module Resqued
|
|
15
15
|
#
|
16
16
|
# Runs in the master process.
|
17
17
|
def initialize(options)
|
18
|
-
@
|
18
|
+
@config_paths = options.fetch(:config_paths)
|
19
19
|
@running_workers = options.fetch(:running_workers) { [] }
|
20
20
|
@socket = options.fetch(:socket)
|
21
21
|
@listener_id = options.fetch(:listener_id) { nil }
|
@@ -25,11 +25,13 @@ module Resqued
|
|
25
25
|
#
|
26
26
|
# Runs in the master process.
|
27
27
|
def exec
|
28
|
-
|
29
|
-
ENV['
|
28
|
+
socket_fd = @socket.to_i
|
29
|
+
ENV['RESQUED_SOCKET'] = socket_fd.to_s
|
30
|
+
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
|
30
31
|
ENV['RESQUED_STATE'] = (@running_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
|
31
32
|
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
|
32
|
-
|
33
|
+
# This may not work in rubies earlier than 1.9.
|
34
|
+
Kernel.exec('resqued-listener', socket_fd => socket_fd)
|
33
35
|
end
|
34
36
|
|
35
37
|
# Public: Given args from #exec, start this listener.
|
@@ -39,7 +41,7 @@ module Resqued
|
|
39
41
|
options[:socket] = Socket.for_fd(socket.to_i)
|
40
42
|
end
|
41
43
|
if path = ENV['RESQUED_CONFIG_PATH']
|
42
|
-
options[:
|
44
|
+
options[:config_paths] = path.split(':')
|
43
45
|
end
|
44
46
|
if state = ENV['RESQUED_STATE']
|
45
47
|
options[:running_workers] = state.split('||').map { |s| Hash[[:pid,:queue].zip(s.split('|'))] }
|
@@ -59,8 +61,9 @@ module Resqued
|
|
59
61
|
trap(:CHLD) { awake }
|
60
62
|
SIGNALS.each { |signal| trap(signal) { SIGNAL_QUEUE << signal ; awake } }
|
61
63
|
@socket.close_on_exec = true
|
64
|
+
write_procline('starting')
|
62
65
|
|
63
|
-
config = Resqued::Config.new(@
|
66
|
+
config = Resqued::Config.new(@config_paths)
|
64
67
|
config.before_fork
|
65
68
|
|
66
69
|
write_procline('running')
|
@@ -201,7 +204,7 @@ module Resqued
|
|
201
204
|
procline = "resqued listener"
|
202
205
|
procline << " #{@listener_id}" if @listener_id
|
203
206
|
procline << " [#{status}]"
|
204
|
-
procline << " #{@
|
207
|
+
procline << " #{@config_paths.join(' ')}"
|
205
208
|
$0 = procline
|
206
209
|
end
|
207
210
|
end
|
data/lib/resqued/master.rb
CHANGED
@@ -15,8 +15,8 @@ module Resqued
|
|
15
15
|
include Resqued::Sleepy
|
16
16
|
|
17
17
|
def initialize(options)
|
18
|
-
@
|
19
|
-
@pidfile
|
18
|
+
@config_paths = options.fetch(:config_paths)
|
19
|
+
@pidfile = options.fetch(:master_pidfile) { nil }
|
20
20
|
@listener_backoff = Backoff.new
|
21
21
|
@listeners_created = 0
|
22
22
|
end
|
@@ -97,12 +97,9 @@ module Resqued
|
|
97
97
|
listener_pids.values
|
98
98
|
end
|
99
99
|
|
100
|
-
attr_reader :config_path
|
101
|
-
attr_reader :pidfile
|
102
|
-
|
103
100
|
def start_listener
|
104
101
|
return if @current_listener || @listener_backoff.wait?
|
105
|
-
@current_listener = ListenerProxy.new(:
|
102
|
+
@current_listener = ListenerProxy.new(:config_paths => @config_paths, :running_workers => all_listeners.map { |l| l.running_workers }.flatten, :listener_id => next_listener_id)
|
106
103
|
@current_listener.run
|
107
104
|
@listener_backoff.started
|
108
105
|
listener_pids[@current_listener.pid] = @current_listener
|
data/lib/resqued/version.rb
CHANGED
data/lib/resqued/worker.rb
CHANGED
@@ -76,8 +76,8 @@ module Resqued
|
|
76
76
|
end
|
77
77
|
resque_worker = Resque::Worker.new(*queues)
|
78
78
|
resque_worker.log "Starting worker #{resque_worker}"
|
79
|
-
resque_worker.term_child = true
|
80
|
-
|
79
|
+
resque_worker.term_child = true if resque_worker.respond_to?('term_child=')
|
80
|
+
Resque.redis.client.reconnect
|
81
81
|
@config.after_fork(resque_worker)
|
82
82
|
resque_worker.work(@interval || 5)
|
83
83
|
exit 0
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resqued
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt Burke
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: kgio
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,39 +27,34 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: resque
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
33
|
+
version: 1.9.0
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
40
|
+
version: 1.9.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: debugger
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rake
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ~>
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,7 +83,6 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: guard-rspec
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
87
|
- - ~>
|
100
88
|
- !ruby/object:Gem::Version
|
@@ -102,7 +90,6 @@ dependencies:
|
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
94
|
- - ~>
|
108
95
|
- !ruby/object:Gem::Version
|
@@ -110,7 +97,6 @@ dependencies:
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: guard-bundler
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
101
|
- - ~>
|
116
102
|
- !ruby/object:Gem::Version
|
@@ -118,7 +104,6 @@ dependencies:
|
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
108
|
- - ~>
|
124
109
|
- !ruby/object:Gem::Version
|
@@ -126,17 +111,15 @@ dependencies:
|
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: rb-fsevent
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - '>='
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '0'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - '>='
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '0'
|
142
125
|
description: Daemon of resque workers
|
@@ -169,26 +152,25 @@ files:
|
|
169
152
|
- exe/resqued-listener
|
170
153
|
homepage: https://github.com
|
171
154
|
licenses: []
|
155
|
+
metadata: {}
|
172
156
|
post_install_message:
|
173
157
|
rdoc_options: []
|
174
158
|
require_paths:
|
175
159
|
- lib
|
176
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
161
|
requirements:
|
179
|
-
- -
|
162
|
+
- - '>='
|
180
163
|
- !ruby/object:Gem::Version
|
181
164
|
version: '0'
|
182
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
-
none: false
|
184
166
|
requirements:
|
185
|
-
- -
|
167
|
+
- - '>='
|
186
168
|
- !ruby/object:Gem::Version
|
187
169
|
version: '0'
|
188
170
|
requirements: []
|
189
171
|
rubyforge_project:
|
190
|
-
rubygems_version:
|
172
|
+
rubygems_version: 2.0.3
|
191
173
|
signing_key:
|
192
|
-
specification_version:
|
174
|
+
specification_version: 4
|
193
175
|
summary: Daemon of resque workers
|
194
176
|
test_files: []
|