resque-pool 0.5.0 → 0.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +71 -3
- data/README.md +59 -22
- data/Rakefile +2 -2
- data/lib/resque/pool.rb +30 -37
- data/lib/resque/pool/cli.rb +27 -24
- data/lib/resque/pool/file_or_hash_loader.rb +55 -0
- data/lib/resque/pool/logging.rb +81 -24
- data/lib/resque/pool/pooled_worker.rb +5 -1
- data/lib/resque/pool/version.rb +1 -1
- metadata +11 -44
- data/features/basic_daemon_config.feature +0 -68
- data/features/step_definitions/daemon_steps.rb +0 -33
- data/features/step_definitions/resque-pool_steps.rb +0 -159
- data/features/support/aruba_daemon_support.rb +0 -76
- data/features/support/env.rb +0 -1
- data/spec/mock_config.rb +0 -6
- data/spec/resque-pool-custom.yml.erb +0 -1
- data/spec/resque-pool.yml +0 -13
- data/spec/resque_pool_spec.rb +0 -202
- data/spec/spec_helper.rb +0 -3
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'aruba/cucumber'
|
2
|
-
require 'aruba/api'
|
3
|
-
require 'aruba/process'
|
4
|
-
|
5
|
-
module Aruba
|
6
|
-
|
7
|
-
module Api
|
8
|
-
|
9
|
-
# this is a horrible hack, to make sure that it's done what it needs to do
|
10
|
-
# before we do our next step
|
11
|
-
def keep_trying(timeout=10, tries=0)
|
12
|
-
puts "Try: #{tries}" if @announce_env
|
13
|
-
yield
|
14
|
-
rescue RSpec::Expectations::ExpectationNotMetError
|
15
|
-
if tries < timeout
|
16
|
-
sleep 1
|
17
|
-
tries += 1
|
18
|
-
retry
|
19
|
-
else
|
20
|
-
raise
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def run_background(cmd)
|
25
|
-
@background = run(cmd)
|
26
|
-
end
|
27
|
-
|
28
|
-
def send_signal(cmd, signal)
|
29
|
-
announce_or_puts "$ kill -#{signal} #{processes[cmd].pid}" if @announce_env
|
30
|
-
processes[cmd].send_signal signal
|
31
|
-
end
|
32
|
-
|
33
|
-
def background_pid
|
34
|
-
@pid_from_pidfile || @background.pid
|
35
|
-
end
|
36
|
-
|
37
|
-
# like all_stdout, but doesn't stop processes first
|
38
|
-
def interactive_stdout
|
39
|
-
only_processes.inject("") { |out, ps| out << ps.stdout(@aruba_keep_ansi) }
|
40
|
-
end
|
41
|
-
|
42
|
-
# like all_stderr, but doesn't stop processes first
|
43
|
-
def interactive_stderr
|
44
|
-
only_processes.inject("") { |out, ps| out << ps.stderr(@aruba_keep_ansi) }
|
45
|
-
end
|
46
|
-
|
47
|
-
# like all_output, but doesn't stop processes first
|
48
|
-
def interactive_output
|
49
|
-
interactive_stdout << interactive_stderr
|
50
|
-
end
|
51
|
-
|
52
|
-
def interpolate_background_pid(string)
|
53
|
-
interpolated = string.gsub('$PID', background_pid.to_s)
|
54
|
-
announce_or_puts interpolated if @announce_env
|
55
|
-
interpolated
|
56
|
-
end
|
57
|
-
|
58
|
-
def kill_all_processes!
|
59
|
-
# stop_processes!
|
60
|
-
#rescue
|
61
|
-
# processes.each {|cmd,process| send_signal(cmd, 'KILL') }
|
62
|
-
# raise
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
class Process
|
68
|
-
def pid
|
69
|
-
@process.pid
|
70
|
-
end
|
71
|
-
def send_signal signal
|
72
|
-
@process.send :send_signal, signal
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
data/spec/mock_config.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
foo: <%= 1+1 %>
|
data/spec/resque-pool.yml
DELETED
data/spec/resque_pool_spec.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
config.after {
|
5
|
-
Object.send(:remove_const, :RAILS_ENV) if defined? RAILS_ENV
|
6
|
-
ENV.delete 'RACK_ENV'
|
7
|
-
ENV.delete 'RAILS_ENV'
|
8
|
-
ENV.delete 'RESQUE_ENV'
|
9
|
-
ENV.delete 'RESQUE_POOL_CONFIG'
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Resque::Pool, "when loading a simple pool configuration" do
|
14
|
-
let(:config) do
|
15
|
-
{ 'foo' => 1, 'bar' => 2, 'foo,bar' => 3, 'bar,foo' => 4, }
|
16
|
-
end
|
17
|
-
subject { Resque::Pool.new(config) }
|
18
|
-
|
19
|
-
context "when ENV['RACK_ENV'] is set" do
|
20
|
-
before { ENV['RACK_ENV'] = 'development' }
|
21
|
-
|
22
|
-
it "should load the values from the Hash" do
|
23
|
-
subject.config["foo"].should == 1
|
24
|
-
subject.config["bar"].should == 2
|
25
|
-
subject.config["foo,bar"].should == 3
|
26
|
-
subject.config["bar,foo"].should == 4
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
describe Resque::Pool, "when loading the pool configuration from a Hash" do
|
33
|
-
|
34
|
-
let(:config) do
|
35
|
-
{
|
36
|
-
'foo' => 8,
|
37
|
-
'test' => { 'bar' => 10, 'foo,bar' => 12 },
|
38
|
-
'development' => { 'baz' => 14, 'foo,bar' => 16 },
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
subject { Resque::Pool.new(config) }
|
43
|
-
|
44
|
-
context "when RAILS_ENV is set" do
|
45
|
-
before { RAILS_ENV = "test" }
|
46
|
-
|
47
|
-
it "should load the default values from the Hash" do
|
48
|
-
subject.config["foo"].should == 8
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should merge the values for the correct RAILS_ENV" do
|
52
|
-
subject.config["bar"].should == 10
|
53
|
-
subject.config["foo,bar"].should == 12
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should not load the values for the other environments" do
|
57
|
-
subject.config["foo,bar"].should == 12
|
58
|
-
subject.config["baz"].should be_nil
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when Rails.env is set" do
|
64
|
-
before(:each) do
|
65
|
-
module Rails; end
|
66
|
-
Rails.stub(:env).and_return('test')
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should load the default values from the Hash" do
|
70
|
-
subject.config["foo"].should == 8
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should merge the values for the correct RAILS_ENV" do
|
74
|
-
subject.config["bar"].should == 10
|
75
|
-
subject.config["foo,bar"].should == 12
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not load the values for the other environments" do
|
79
|
-
subject.config["foo,bar"].should == 12
|
80
|
-
subject.config["baz"].should be_nil
|
81
|
-
end
|
82
|
-
|
83
|
-
after(:all) { Object.send(:remove_const, :Rails) }
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
context "when ENV['RESQUE_ENV'] is set" do
|
88
|
-
before { ENV['RESQUE_ENV'] = 'development' }
|
89
|
-
it "should load the config for that environment" do
|
90
|
-
subject.config["foo"].should == 8
|
91
|
-
subject.config["foo,bar"].should == 16
|
92
|
-
subject.config["baz"].should == 14
|
93
|
-
subject.config["bar"].should be_nil
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when there is no environment" do
|
98
|
-
it "should load the default values only" do
|
99
|
-
subject.config["foo"].should == 8
|
100
|
-
subject.config["bar"].should be_nil
|
101
|
-
subject.config["foo,bar"].should be_nil
|
102
|
-
subject.config["baz"].should be_nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
describe Resque::Pool, "given no configuration" do
|
109
|
-
subject { Resque::Pool.new(nil) }
|
110
|
-
it "should have no worker types" do
|
111
|
-
subject.config.should == {}
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe Resque::Pool, "when loading the pool configuration from a file" do
|
116
|
-
|
117
|
-
subject { Resque::Pool.new("spec/resque-pool.yml") }
|
118
|
-
|
119
|
-
context "when RAILS_ENV is set" do
|
120
|
-
before { RAILS_ENV = "test" }
|
121
|
-
|
122
|
-
it "should load the default YAML" do
|
123
|
-
subject.config["foo"].should == 1
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should merge the YAML for the correct RAILS_ENV" do
|
127
|
-
subject.config["bar"].should == 5
|
128
|
-
subject.config["foo,bar"].should == 3
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should not load the YAML for the other environments" do
|
132
|
-
subject.config["foo"].should == 1
|
133
|
-
subject.config["bar"].should == 5
|
134
|
-
subject.config["foo,bar"].should == 3
|
135
|
-
subject.config["baz"].should be_nil
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when ENV['RACK_ENV'] is set" do
|
141
|
-
before { ENV['RACK_ENV'] = 'development' }
|
142
|
-
it "should load the config for that environment" do
|
143
|
-
subject.config["foo"].should == 1
|
144
|
-
subject.config["foo,bar"].should == 4
|
145
|
-
subject.config["baz"].should == 23
|
146
|
-
subject.config["bar"].should be_nil
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "when there is no environment" do
|
151
|
-
it "should load the default values only" do
|
152
|
-
subject.config["foo"].should == 1
|
153
|
-
subject.config["bar"].should be_nil
|
154
|
-
subject.config["foo,bar"].should be_nil
|
155
|
-
subject.config["baz"].should be_nil
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "when a custom file is specified" do
|
160
|
-
before { ENV["RESQUE_POOL_CONFIG"] = 'spec/resque-pool-custom.yml.erb' }
|
161
|
-
subject { Resque::Pool.new(Resque::Pool.choose_config_file) }
|
162
|
-
it "should find the right file, and parse the ERB" do
|
163
|
-
subject.config["foo"].should == 2
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
describe Resque::Pool, "given after_prefork hook" do
|
170
|
-
subject { Resque::Pool.new(nil) }
|
171
|
-
|
172
|
-
context "with a single hook" do
|
173
|
-
before { Resque::Pool.after_prefork { @called = true } }
|
174
|
-
|
175
|
-
it "should call prefork" do
|
176
|
-
subject.call_after_prefork!
|
177
|
-
@called.should == true
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context "with a single hook by attribute writer" do
|
182
|
-
before { Resque::Pool.after_prefork = Proc.new { @called = true } }
|
183
|
-
|
184
|
-
it "should call prefork" do
|
185
|
-
subject.call_after_prefork!
|
186
|
-
@called.should == true
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "with multiple hooks" do
|
191
|
-
before {
|
192
|
-
Resque::Pool.after_prefork { @called_first = true }
|
193
|
-
Resque::Pool.after_prefork { @called_second = true }
|
194
|
-
}
|
195
|
-
|
196
|
-
it "should call both" do
|
197
|
-
subject.call_after_prefork!
|
198
|
-
@called_first.should == true
|
199
|
-
@called_second.should == true
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
data/spec/spec_helper.rb
DELETED