resque-pool 0.0.10.0 → 0.0.12.0.alpha
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/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +20 -0
- data/README.md +17 -13
- data/Rakefile +3 -0
- data/bin/resque-pool +5 -0
- data/config/alternate.yml +4 -0
- data/config/resque-pool.yml +7 -0
- data/examples/Rakefile +8 -0
- data/examples/chef_cookbook/recipes/default.rb +38 -0
- data/examples/chef_cookbook/templates/default/initd.erb +61 -0
- data/examples/chef_cookbook/templates/default/monitrc.erb +6 -0
- data/examples/rails-resque.rake +22 -0
- data/examples/resque-pool.yml +4 -0
- data/lib/resque/pool/cli.rb +94 -0
- data/lib/resque/pool/version.rb +5 -0
- data/resque-pool.gemspec +29 -0
- data/spec/mock_config.rb +6 -0
- data/spec/resque-pool.yml +13 -0
- data/spec/resque_pool_spec.rb +127 -0
- data/spec/spec_helper.rb +3 -0
- metadata +85 -18
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
resque-pool (0.0.12.0.alpha)
|
5
|
+
rake
|
6
|
+
resque (~> 1.10)
|
7
|
+
trollop (~> 1.16)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
SystemTimer (1.2.1)
|
13
|
+
diff-lcs (1.1.2)
|
14
|
+
json (1.4.6)
|
15
|
+
rack (1.2.1)
|
16
|
+
rake (0.8.7)
|
17
|
+
redis (2.1.1)
|
18
|
+
redis-namespace (0.8.0)
|
19
|
+
redis (< 3.0.0)
|
20
|
+
resque (1.10.0)
|
21
|
+
json (~> 1.4.6)
|
22
|
+
redis-namespace (~> 0.8.0)
|
23
|
+
sinatra (>= 0.9.2)
|
24
|
+
vegas (~> 0.1.2)
|
25
|
+
rspec (2.4.0)
|
26
|
+
rspec-core (~> 2.4.0)
|
27
|
+
rspec-expectations (~> 2.4.0)
|
28
|
+
rspec-mocks (~> 2.4.0)
|
29
|
+
rspec-core (2.4.0)
|
30
|
+
rspec-expectations (2.4.0)
|
31
|
+
diff-lcs (~> 1.1.2)
|
32
|
+
rspec-mocks (2.4.0)
|
33
|
+
sinatra (1.1.2)
|
34
|
+
rack (~> 1.1)
|
35
|
+
tilt (~> 1.2)
|
36
|
+
tilt (1.2.1)
|
37
|
+
trollop (1.16.2)
|
38
|
+
vegas (0.1.8)
|
39
|
+
rack (>= 1.0.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
SystemTimer
|
46
|
+
bundler (~> 1.0)
|
47
|
+
rake
|
48
|
+
resque (~> 1.10)
|
49
|
+
resque-pool!
|
50
|
+
rspec
|
51
|
+
trollop (~> 1.16)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2010 by Nicholas Evans <nick@ekenosen.net>, et al.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.md
CHANGED
@@ -21,9 +21,9 @@ Benefits
|
|
21
21
|
How to use
|
22
22
|
-----------
|
23
23
|
|
24
|
-
To configure resque-pool,
|
25
|
-
|
26
|
-
|
24
|
+
To configure resque-pool, create a `config/resque-pool.yml` with your worker
|
25
|
+
counts. To use resque-pool, require its rake tasks (`resque/pool/tasks`) in
|
26
|
+
your rake file, and run `resque-pool`
|
27
27
|
|
28
28
|
The YAML file supports both using root level defaults as well as environment
|
29
29
|
specific overrides (`RACK_ENV`, `RAILS_ENV`, and `RESQUE_ENV` environment
|
@@ -56,7 +56,7 @@ and in `lib/tasks/resque.rake`:
|
|
56
56
|
|
57
57
|
Then you can start the queues via:
|
58
58
|
|
59
|
-
|
59
|
+
resque-pool --environment production
|
60
60
|
|
61
61
|
This will start up seven worker processes, one exclusively for the foo queue,
|
62
62
|
two exclusively for the bar queue, and four workers looking at all queues in
|
@@ -108,32 +108,36 @@ via `QUIT`.
|
|
108
108
|
Other Features
|
109
109
|
--------------
|
110
110
|
|
111
|
+
You can run resque-pool as a daemon via `--daemon`. It will default to placing
|
112
|
+
the pidfile and logfiles in the rails default locations, so you may want to
|
113
|
+
configure that. See `resque-pool --help` for more options. An example init.d
|
114
|
+
script and monitrc are included, as erb templates.
|
115
|
+
|
116
|
+
You can also run `resque-pool` via the `resque:pool` rake task.
|
117
|
+
|
111
118
|
Workers will watch the pool master, and gracefully shutdown if the master
|
112
119
|
process dies (for whatever reason) before them.
|
113
120
|
|
114
121
|
You can specify an alternate config file by setting the `RESQUE_POOL_CONFIG`
|
115
122
|
environment variable like so:
|
116
123
|
|
117
|
-
|
124
|
+
resque-pool -c /path/to/my/config.yml
|
118
125
|
|
119
126
|
TODO
|
120
127
|
-----
|
121
128
|
|
122
|
-
*
|
123
|
-
|
124
|
-
|
125
|
-
"logs" by writing to $stdout, this is really no more than redirecting stdout
|
126
|
-
to the appropriate logfile.
|
127
|
-
* (optionally) daemonize, setting a PID file somewhere. configurable, of
|
128
|
-
course, but default to `tmp/pids/resque-pool.pid`.
|
129
|
+
* cmd line option for non-rake loading
|
130
|
+
* cmd line option for preload ruby file
|
131
|
+
* perhaps provide Unix style log formatter
|
129
132
|
* recover gracefully from a malformed config file (on startup and HUP)
|
130
133
|
* procline for malformed config file, graceful shutdown... and other states?
|
134
|
+
* web interface for adding and removing workers (etc)
|
131
135
|
* figure out a good automated way to test this (cucumber or rspec?)
|
136
|
+
* rename to `resque-squad`?
|
132
137
|
* clean up the code (I stole most of it from unicorn, and it's still a bit
|
133
138
|
bastardized); excessive use of vim foldmarkers are a code smell.
|
134
139
|
* rdoc
|
135
140
|
* incorporate resque-batchworker features? (v2.0)
|
136
|
-
* web interface for adding and removing workers (etc) (v2.0)
|
137
141
|
|
138
142
|
Contributors
|
139
143
|
-------------
|
data/Rakefile
ADDED
data/bin/resque-pool
ADDED
data/examples/Rakefile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# If you have redis running on the standard port on localhost, then you can
|
2
|
+
# test out resque-pool in the examples directory by running:
|
3
|
+
#
|
4
|
+
# rake --trace resque:pool
|
5
|
+
#
|
6
|
+
# And then you can poke and prod the various processes with signals and edit
|
7
|
+
# the config file, etc.
|
8
|
+
require 'resque/pool/tasks'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
if ['solo', 'util'].include?(node[:instance_role])
|
2
|
+
|
3
|
+
template "/etc/monit.d/#{app}_resque.monitrc" do
|
4
|
+
owner 'root'
|
5
|
+
group 'root'
|
6
|
+
mode 0644
|
7
|
+
source "monitrc.erb"
|
8
|
+
variables({
|
9
|
+
:app_name => app,
|
10
|
+
#:max_mem => "400 MB",
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
template "/etc/init.d/#{app}_resque" do
|
15
|
+
owner 'root'
|
16
|
+
group 'root'
|
17
|
+
mode 0744
|
18
|
+
source "initd.rb"
|
19
|
+
variables({
|
20
|
+
:app_name => app,
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
execute "enable-resque" do
|
25
|
+
command "rc-update add #{app}_resque default"
|
26
|
+
action :run
|
27
|
+
not_if "rc-update show | grep -q #{app}_resque.*default"
|
28
|
+
end
|
29
|
+
|
30
|
+
execute "start-resque" do
|
31
|
+
command %Q{/etc/init.d/#{app}_resque start}
|
32
|
+
end
|
33
|
+
|
34
|
+
execute "ensure-resque-is-setup-with-monit" do
|
35
|
+
command %Q{monit reload}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/bin/sh -e
|
2
|
+
# Copyright (C) nicholas a. evans <nick@ekenosen.net>
|
3
|
+
# See LICENSE.txt
|
4
|
+
|
5
|
+
### BEGIN INIT INFO
|
6
|
+
# Provides: resque-pool-<%= @app_name %>
|
7
|
+
# Required-Start: $local_fs $remote_fs $network
|
8
|
+
# Required-Stop: $local_fs $remote_fs $network
|
9
|
+
# Default-Start: 2 3 4 5
|
10
|
+
# Default-Stop: 0 1 6
|
11
|
+
# Short-Description: resque-pool init script for <%= @app_name %>
|
12
|
+
# Description: resque-pool manages the resque workers
|
13
|
+
### END INIT INFO
|
14
|
+
|
15
|
+
# configure these values here or in /etc/default/resque-pool
|
16
|
+
app_name="<%= @app_name %>"
|
17
|
+
app_dir="/data/${app_name}/current"
|
18
|
+
run_as_user="deploy"
|
19
|
+
pidfile="/var/run/resque-pool-${app_name}.pid"
|
20
|
+
sleep_time_during_restart=5
|
21
|
+
bundler="bundle"
|
22
|
+
environment="production"
|
23
|
+
stdout_log="${app_dir}/log/resque-pool-${app_name}.stdout.log"
|
24
|
+
stderr_log="${app_dir}/log/resque-pool-${app_name}.stderr.log"
|
25
|
+
|
26
|
+
# override above values, and set any other env variables you need
|
27
|
+
if [ -f /etc/default/resque-pool ] ; then
|
28
|
+
. /etc/default/resque-pool
|
29
|
+
fi
|
30
|
+
|
31
|
+
case "$1" in
|
32
|
+
start)
|
33
|
+
# I'm assuming that you are using bundler. If you are using rip or
|
34
|
+
# something else, you'll need to change this. Remember to
|
35
|
+
# keep the double-dash; e.g.: --startas CMD -- ARGS
|
36
|
+
start-stop-daemon --start --pidfile ${pidfile} \
|
37
|
+
--chuid ${run_as_user} --chdir ${app_dir} \
|
38
|
+
--startas ${bundler} -- exec \
|
39
|
+
resque-pool -d -p ${pidfile} -E ${environment} -o ${stdout_log} -e ${stderr_log}
|
40
|
+
;;
|
41
|
+
graceful-stop)
|
42
|
+
start-stop-daemon --stop --pidfile ${pidfile} --signal QUIT
|
43
|
+
;;
|
44
|
+
quick-stop)
|
45
|
+
start-stop-daemon --stop --pidfile ${pidfile} --signal INT
|
46
|
+
;;
|
47
|
+
stop)
|
48
|
+
start-stop-daemon --stop --pidfile ${pidfile} --signal QUIT/30/INT/10/KILL/5
|
49
|
+
;;
|
50
|
+
restart)
|
51
|
+
$0 stop
|
52
|
+
sleep ${sleep_time_during_restart}
|
53
|
+
$0 start
|
54
|
+
;;
|
55
|
+
*)
|
56
|
+
echo "Usage: $0 {start|stop|graceful-stop|quick-stop|restart}"
|
57
|
+
exit 1
|
58
|
+
;;
|
59
|
+
esac
|
60
|
+
|
61
|
+
# vim:ft=sh
|
@@ -0,0 +1,6 @@
|
|
1
|
+
check process <%= @app_name %>_resque
|
2
|
+
with pidfile /var/run/<%= @app_name %>_resque.pid
|
3
|
+
start program = "/etc/init.d/<%= @app_name %>_resque start" with timeout 90 seconds as uid deploy and gid deploy
|
4
|
+
stop program = "/etc/init.d/<%= @app_name %>_resque stop" with timeout 90 seconds
|
5
|
+
#if totalmem is greater than <%= @max_mem || "300 MB" %> for 10 cycles then restart # eating up memory?
|
6
|
+
group resque
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'resque/pool/tasks'
|
2
|
+
|
3
|
+
# this task will get called before resque:pool:setup
|
4
|
+
# preload the rails environment in the pool master
|
5
|
+
task "resque:setup" => :environment do
|
6
|
+
# generic worker setup, e.g. Hoptoad for failed jobs
|
7
|
+
end
|
8
|
+
|
9
|
+
task "resque:pool:setup" do
|
10
|
+
# close any sockets or files in pool master
|
11
|
+
ActiveRecord::Base.connection.disconnect!
|
12
|
+
|
13
|
+
# and re-open them in the resque worker parent
|
14
|
+
Resque::Pool.after_prefork do |job|
|
15
|
+
ActiveRecord::Base.establish_connection
|
16
|
+
end
|
17
|
+
|
18
|
+
# you could also re-open them in the resque worker child, using
|
19
|
+
# Resque.after_fork, but that probably isn't necessary, and
|
20
|
+
# Resque::Pool.after_prefork should be faster, since it won't run
|
21
|
+
# for every single job.
|
22
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
class Pool
|
5
|
+
module CLI
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def run
|
9
|
+
opts = parse_options
|
10
|
+
daemonize if opts[:daemon]
|
11
|
+
pidfile opts[:pidfile]
|
12
|
+
redirect opts
|
13
|
+
setup_environment opts
|
14
|
+
start_pool
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_options
|
18
|
+
opts = Trollop::options do
|
19
|
+
version "resque-pool #{Resque::Pool::VERSION} (c) nicholas a. evans"
|
20
|
+
banner <<-EOS
|
21
|
+
resque-pool is the best way to manage a group (pool) of resque workers
|
22
|
+
|
23
|
+
When daemonized, stdout and stderr default to resque-pool.stdxxx.log files in
|
24
|
+
the log directory and pidfile defaults to resque-pool.pid in the current dir.
|
25
|
+
|
26
|
+
Usage:
|
27
|
+
resque-pool [options]
|
28
|
+
where [options] are:
|
29
|
+
EOS
|
30
|
+
opt :config, "Alternate path to config file", :short => "-c"
|
31
|
+
opt :daemon, "Run as a background daemon", :default => false, :short => "-d"
|
32
|
+
opt :stdout, "Redirect stdout to logfile", :type => String, :short => '-o'
|
33
|
+
opt :stderr, "Redirect stderr to logfile", :type => String, :short => '-e'
|
34
|
+
opt :nosync, "Don't sync logfiles on every write"
|
35
|
+
opt :pidfile, "PID file location", :type => String, :short => "-p"
|
36
|
+
opt :environment, "Set RAILS_ENV/RACK_ENV/RESQUE_ENV",
|
37
|
+
:default => "development", :short => "-E"
|
38
|
+
end
|
39
|
+
if opts[:daemon]
|
40
|
+
opts[:stdout] ||= "log/resque-pool.stdout.log"
|
41
|
+
opts[:stderr] ||= "log/resque-pool.stderr.log"
|
42
|
+
opts[:pidfile] ||= "resque-pool.pid"
|
43
|
+
end
|
44
|
+
opts
|
45
|
+
end
|
46
|
+
|
47
|
+
def daemonize
|
48
|
+
raise 'First fork failed' if (pid = fork) == -1
|
49
|
+
exit unless pid.nil?
|
50
|
+
Process.setsid
|
51
|
+
raise 'Second fork failed' if (pid = fork) == -1
|
52
|
+
exit unless pid.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def pidfile(pidfile)
|
56
|
+
pid = Process.pid
|
57
|
+
if pidfile
|
58
|
+
if File.exist? pidfile
|
59
|
+
raise "Pidfile already exists at #{pidfile}. Check to make sure process is not already running."
|
60
|
+
end
|
61
|
+
File.open pidfile, "w" do |f|
|
62
|
+
f.write pid
|
63
|
+
end
|
64
|
+
at_exit do
|
65
|
+
if Process.pid == pid
|
66
|
+
File.delete pidfile
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def redirect(opts)
|
73
|
+
$stdin.reopen '/dev/null' if opts[:daemon]
|
74
|
+
$stdout.reopen opts[:stdout], "a" if opts[:stdout] && !opts[:stdout].empty?
|
75
|
+
$stderr.reopen opts[:stderr], "a" if opts[:stderr] && !opts[:stderr].empty?
|
76
|
+
$stdout.sync = $stderr.sync = true unless opts[:nosync]
|
77
|
+
end
|
78
|
+
|
79
|
+
def setup_environment(opts)
|
80
|
+
ENV["RACK_ENV"] = ENV["RAILS_ENV"] = ENV["RESQUE_ENV"] = opts[:environment]
|
81
|
+
puts "Running in #{opts[:environment]} environment."
|
82
|
+
ENV["RESQUE_POOL_CONFIG"] = opts[:config] if opts[:config]
|
83
|
+
end
|
84
|
+
|
85
|
+
def start_pool
|
86
|
+
require 'rake'
|
87
|
+
require 'resque/pool/tasks'
|
88
|
+
Rake.application["resque:pool"].invoke
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/resque-pool.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "resque/pool/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "resque-pool"
|
7
|
+
s.version = Resque::Pool::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["nicholas a. evans",]
|
10
|
+
s.email = ["nick@ekenosen.net"]
|
11
|
+
s.homepage = "http://github.com/nevans/resque-pool"
|
12
|
+
s.summary = "quickly and easily fork a pool of resque workers"
|
13
|
+
s.description = <<-EOF
|
14
|
+
quickly and easily fork a pool of resque workers,
|
15
|
+
saving memory (w/REE) and monitoring their uptime
|
16
|
+
EOF
|
17
|
+
|
18
|
+
s.add_dependency "resque", "~> 1.10"
|
19
|
+
s.add_dependency "trollop", "~> 1.16"
|
20
|
+
s.add_dependency "rake"
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "SystemTimer" # to silence redis gem's warning
|
23
|
+
s.add_development_dependency "bundler", "~> 1.0"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|
data/spec/mock_config.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
Spec::Runner.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
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Resque::Pool, "when loading a simple pool configuration" do
|
13
|
+
let(:config) do
|
14
|
+
{ 'foo' => 1, 'bar' => 2, 'foo,bar' => 3, 'bar,foo' => 4, }
|
15
|
+
end
|
16
|
+
subject { Resque::Pool.new(config) }
|
17
|
+
|
18
|
+
context "when ENV['RACK_ENV'] is set" do
|
19
|
+
before { ENV['RACK_ENV'] = 'development' }
|
20
|
+
|
21
|
+
it "should load the values from the Hash" do
|
22
|
+
subject.config["foo"].should == 1
|
23
|
+
subject.config["bar"].should == 2
|
24
|
+
subject.config["foo,bar"].should == 3
|
25
|
+
subject.config["bar,foo"].should == 4
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Resque::Pool, "when loading the pool configuration from a Hash" do
|
32
|
+
|
33
|
+
let(:config) do
|
34
|
+
{
|
35
|
+
'foo' => 8,
|
36
|
+
'test' => { 'bar' => 10, 'foo,bar' => 12 },
|
37
|
+
'development' => { 'baz' => 14, 'foo,bar' => 16 },
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { Resque::Pool.new(config) }
|
42
|
+
|
43
|
+
context "when RAILS_ENV is set" do
|
44
|
+
before { RAILS_ENV = "test" }
|
45
|
+
|
46
|
+
it "should load the default values from the Hash" do
|
47
|
+
subject.config["foo"].should == 8
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should merge the values for the correct RAILS_ENV" do
|
51
|
+
subject.config["bar"].should == 10
|
52
|
+
subject.config["foo,bar"].should == 12
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not load the values for the other environments" do
|
56
|
+
subject.config["foo,bar"].should == 12
|
57
|
+
subject.config["baz"].should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when ENV['RESQUE_ENV'] is set" do
|
63
|
+
before { ENV['RESQUE_ENV'] = 'development' }
|
64
|
+
it "should load the config for that environment" do
|
65
|
+
subject.config["foo"].should == 8
|
66
|
+
subject.config["foo,bar"].should == 16
|
67
|
+
subject.config["baz"].should == 14
|
68
|
+
subject.config["bar"].should be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when there is no environment" do
|
73
|
+
it "should load the default values only" do
|
74
|
+
subject.config["foo"].should == 8
|
75
|
+
subject.config["bar"].should be_nil
|
76
|
+
subject.config["foo,bar"].should be_nil
|
77
|
+
subject.config["baz"].should be_nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe Resque::Pool, "when loading the pool configuration from a file" do
|
84
|
+
|
85
|
+
subject { Resque::Pool.new("spec/resque-pool.yml") }
|
86
|
+
|
87
|
+
context "when RAILS_ENV is set" do
|
88
|
+
before { RAILS_ENV = "test" }
|
89
|
+
|
90
|
+
it "should load the default YAML" do
|
91
|
+
subject.config["foo"].should == 1
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should merge the YAML for the correct RAILS_ENV" do
|
95
|
+
subject.config["bar"].should == 5
|
96
|
+
subject.config["foo,bar"].should == 3
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not load the YAML for the other environments" do
|
100
|
+
subject.config["foo"].should == 1
|
101
|
+
subject.config["bar"].should == 5
|
102
|
+
subject.config["foo,bar"].should == 3
|
103
|
+
subject.config["baz"].should be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when ENV['RACK_ENV'] is set" do
|
109
|
+
before { ENV['RACK_ENV'] = 'development' }
|
110
|
+
it "should load the config for that environment" do
|
111
|
+
subject.config["foo"].should == 1
|
112
|
+
subject.config["foo,bar"].should == 4
|
113
|
+
subject.config["baz"].should == 23
|
114
|
+
subject.config["bar"].should be_nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when there is no environment" do
|
119
|
+
it "should load the default values only" do
|
120
|
+
subject.config["foo"].should == 1
|
121
|
+
subject.config["bar"].should be_nil
|
122
|
+
subject.config["foo,bar"].should be_nil
|
123
|
+
subject.config["baz"].should be_nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1851332306
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
9
|
+
- 12
|
10
10
|
- 0
|
11
|
-
|
11
|
+
- alpha
|
12
|
+
version: 0.0.12.0.alpha
|
12
13
|
platform: ruby
|
13
14
|
authors:
|
14
15
|
- nicholas a. evans
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date:
|
20
|
+
date: 2011-01-11 00:00:00 -05:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
@@ -35,9 +36,38 @@ dependencies:
|
|
35
36
|
type: :runtime
|
36
37
|
version_requirements: *id001
|
37
38
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
+
name: trollop
|
39
40
|
prerelease: false
|
40
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 47
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 16
|
50
|
+
version: "1.16"
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
41
71
|
none: false
|
42
72
|
requirements:
|
43
73
|
- - ">="
|
@@ -47,11 +77,25 @@ dependencies:
|
|
47
77
|
- 0
|
48
78
|
version: "0"
|
49
79
|
type: :development
|
50
|
-
version_requirements: *
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: SystemTimer
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
51
95
|
- !ruby/object:Gem::Dependency
|
52
96
|
name: bundler
|
53
97
|
prerelease: false
|
54
|
-
requirement: &
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
55
99
|
none: false
|
56
100
|
requirements:
|
57
101
|
- - ~>
|
@@ -62,22 +106,43 @@ dependencies:
|
|
62
106
|
- 0
|
63
107
|
version: "1.0"
|
64
108
|
type: :development
|
65
|
-
version_requirements: *
|
109
|
+
version_requirements: *id006
|
66
110
|
description: " quickly and easily fork a pool of resque workers,\n saving memory (w/REE) and monitoring their uptime\n"
|
67
111
|
email:
|
68
112
|
- nick@ekenosen.net
|
69
|
-
executables:
|
70
|
-
|
113
|
+
executables:
|
114
|
+
- resque-pool
|
71
115
|
extensions: []
|
72
116
|
|
73
117
|
extra_rdoc_files: []
|
74
118
|
|
75
119
|
files:
|
120
|
+
- .gitignore
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/resque-pool
|
127
|
+
- config/alternate.yml
|
128
|
+
- config/resque-pool.yml
|
129
|
+
- examples/Rakefile
|
130
|
+
- examples/chef_cookbook/recipes/default.rb
|
131
|
+
- examples/chef_cookbook/templates/default/initd.erb
|
132
|
+
- examples/chef_cookbook/templates/default/monitrc.erb
|
133
|
+
- examples/rails-resque.rake
|
134
|
+
- examples/resque-pool.yml
|
76
135
|
- lib/resque/pool.rb
|
77
|
-
- lib/resque/pool/
|
78
|
-
- lib/resque/pool/pooled_worker.rb
|
136
|
+
- lib/resque/pool/cli.rb
|
79
137
|
- lib/resque/pool/logging.rb
|
80
|
-
-
|
138
|
+
- lib/resque/pool/pooled_worker.rb
|
139
|
+
- lib/resque/pool/tasks.rb
|
140
|
+
- lib/resque/pool/version.rb
|
141
|
+
- resque-pool.gemspec
|
142
|
+
- spec/mock_config.rb
|
143
|
+
- spec/resque-pool.yml
|
144
|
+
- spec/resque_pool_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
81
146
|
has_rdoc: true
|
82
147
|
homepage: http://github.com/nevans/resque-pool
|
83
148
|
licenses: []
|
@@ -99,12 +164,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
165
|
none: false
|
101
166
|
requirements:
|
102
|
-
- - "
|
167
|
+
- - ">"
|
103
168
|
- !ruby/object:Gem::Version
|
104
|
-
hash:
|
169
|
+
hash: 25
|
105
170
|
segments:
|
106
|
-
-
|
107
|
-
|
171
|
+
- 1
|
172
|
+
- 3
|
173
|
+
- 1
|
174
|
+
version: 1.3.1
|
108
175
|
requirements: []
|
109
176
|
|
110
177
|
rubyforge_project:
|