resque_manager 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.markdown +417 -0
- data/Rakefile +41 -0
- data/app/assets/images/resque_manager/idle.png +0 -0
- data/app/assets/images/resque_manager/poll.png +0 -0
- data/app/assets/images/resque_manager/working.png +0 -0
- data/app/assets/javascripts/resque_manager/application.js +15 -0
- data/app/assets/javascripts/resque_manager/jquery-1.3.2.min.js +19 -0
- data/app/assets/javascripts/resque_manager/jquery.relatize_date.js +95 -0
- data/app/assets/javascripts/resque_manager/ranger.js +24 -0
- data/app/assets/stylesheets/resque_manager/application.css +14 -0
- data/app/assets/stylesheets/resque_manager/resque/resque.css +93 -0
- data/app/assets/stylesheets/resque_manager/resque/resque_reset.css +48 -0
- data/app/assets/stylesheets/resque_manager/resque_cleaner/cleaner.css +62 -0
- data/app/controllers/resque_manager/resque_controller.rb +313 -0
- data/app/helpers/resque_manager/application_helper.rb +4 -0
- data/app/helpers/resque_manager/resque_helper.rb +142 -0
- data/app/models/resque_manager/paginate.rb +54 -0
- data/app/views/layouts/resque_manager/application.html.erb +37 -0
- data/app/views/resque_manager/resque/_key.html.erb +17 -0
- data/app/views/resque_manager/resque/_limiter.html.erb +12 -0
- data/app/views/resque_manager/resque/_next_more.html.erb +10 -0
- data/app/views/resque_manager/resque/_paginate.html.erb +53 -0
- data/app/views/resque_manager/resque/_queues.html.erb +59 -0
- data/app/views/resque_manager/resque/_status_styles.erb +98 -0
- data/app/views/resque_manager/resque/_workers.html.erb +138 -0
- data/app/views/resque_manager/resque/_working.html.erb +69 -0
- data/app/views/resque_manager/resque/cleaner.html.erb +41 -0
- data/app/views/resque_manager/resque/cleaner_exec.html.erb +6 -0
- data/app/views/resque_manager/resque/cleaner_list.html.erb +172 -0
- data/app/views/resque_manager/resque/delayed.html.erb +35 -0
- data/app/views/resque_manager/resque/delayed_timestamp.html.erb +26 -0
- data/app/views/resque_manager/resque/error.erb +1 -0
- data/app/views/resque_manager/resque/overview.html.erb +4 -0
- data/app/views/resque_manager/resque/schedule.html.erb +96 -0
- data/app/views/resque_manager/resque/stats.html.erb +62 -0
- data/app/views/resque_manager/resque/status.html.erb +57 -0
- data/app/views/resque_manager/resque/statuses.html.erb +72 -0
- data/app/views/resque_manager/resque/workers.html.erb +1 -0
- data/config/routes.rb +38 -0
- data/config/sample_redis.yml +43 -0
- data/config/sample_resque_manager.yml +23 -0
- data/lib/resque_manager/engine.rb +9 -0
- data/lib/resque_manager/overrides/resque/failure/redis.rb +11 -0
- data/lib/resque_manager/overrides/resque/job.rb +69 -0
- data/lib/resque_manager/overrides/resque/resque.rb +8 -0
- data/lib/resque_manager/overrides/resque/worker.rb +291 -0
- data/lib/resque_manager/overrides/resque_scheduler/resque_scheduler.rb +58 -0
- data/lib/resque_manager/overrides/resque_status/chained_status.rb +46 -0
- data/lib/resque_manager/overrides/resque_status/hash.rb +12 -0
- data/lib/resque_manager/overrides/resque_status/status.rb +161 -0
- data/lib/resque_manager/recipes.rb +185 -0
- data/lib/resque_manager/version.rb +3 -0
- data/lib/resque_manager.rb +47 -0
- data/lib/tasks/failure.rake +8 -0
- data/lib/tasks/scheduler.rake +11 -0
- data/lib/tasks/worker.rake +129 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/development.log +5045 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/C2A/A10/sprockets%2Fb2e622954654f415590723e9b882063e +0 -0
- data/test/dummy/tmp/cache/assets/C60/1D0/sprockets%2F8ed12e4193473760f95b973567a8c206 +0 -0
- data/test/dummy/tmp/cache/assets/CA1/970/sprockets%2Fc387148880e015d1eab0dc838b326022 +0 -0
- data/test/dummy/tmp/cache/assets/CAE/930/sprockets%2Fe227278d3c65d8aa1159da720263f771 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDC/E30/sprockets%2Fe1207380d69eeee3284e02636c26f24a +0 -0
- data/test/dummy/tmp/cache/assets/CF1/720/sprockets%2Fd91a5918f5aa43a43c8135a67c78e989 +0 -0
- data/test/dummy/tmp/cache/assets/D0E/820/sprockets%2F00c6cc9dc46bf64347b3775d7d15541b +0 -0
- data/test/dummy/tmp/cache/assets/D16/180/sprockets%2F73d6fa09352cb76ac81e1683e832b93f +0 -0
- data/test/dummy/tmp/cache/assets/D27/170/sprockets%2Fec164819553e2e5b28f1efc9bd970978 +0 -0
- data/test/dummy/tmp/cache/assets/D2B/DA0/sprockets%2F989465d3ea8575dd0b54981a9e8add38 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D37/1F0/sprockets%2F97119b908ebed2633edfd00ac90d9011 +0 -0
- data/test/dummy/tmp/cache/assets/D38/FB0/sprockets%2F74e5ba1cca7a1470d53c54fb60368b78 +0 -0
- data/test/dummy/tmp/cache/assets/D42/4E0/sprockets%2F0fa6e3c14356aa527d68a8d56fa37f28 +0 -0
- data/test/dummy/tmp/cache/assets/D43/C20/sprockets%2F1efd074fd1074b3dc88145b480ff961f +0 -0
- data/test/dummy/tmp/cache/assets/D46/CD0/sprockets%2F67f1ef70e7ede542318b8d55e25b16c3 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D68/080/sprockets%2Fa26f2ae225aa4b87c462d540c7cf43f9 +0 -0
- data/test/dummy/tmp/cache/assets/D9A/B20/sprockets%2F0eddc19d46318e2e286cc171ae4cc73e +0 -0
- data/test/dummy/tmp/cache/assets/DA4/900/sprockets%2F515bf984438c6ec4b8a515fcc13baf8e +0 -0
- data/test/dummy/tmp/cache/assets/DBD/070/sprockets%2F60ffef45ddefd5c7746d17977fff0717 +0 -0
- data/test/dummy/tmp/cache/assets/DD7/AC0/sprockets%2Fc7c983c5c607dbfdb726eecc36146ca9 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DF5/480/sprockets%2Fea4f3c726fc1046cad1ad243faf84e7d +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E2B/7A0/sprockets%2Fd44ef07be0aa6d5b5dea4d37d7f72b4f +0 -0
- data/test/functional/resque_manager/resque_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/resque_manager_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/resque_manager/resque_helper_test.rb +6 -0
- metadata +307 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
# ====================================
|
2
|
+
# Resque TASKS
|
3
|
+
# ====================================
|
4
|
+
|
5
|
+
#You must set the path to your rake executable in your deploy.rb file.
|
6
|
+
#ex.
|
7
|
+
# set :rake, "/opt/ruby-enterprise-1.8.6-20090421/bin/rake"
|
8
|
+
#Optionally, set resque_worker_rake. This will be used for the resque:work task if set.
|
9
|
+
#This allows you to set alternate options, particularly useful for jruby.
|
10
|
+
#ex.
|
11
|
+
#go through jexec so we get the right path and java settings
|
12
|
+
#in deploy.rb
|
13
|
+
# set :rake, "script/jexec rake" #
|
14
|
+
# in initializer
|
15
|
+
# config.resque_worker_rake = "script/jexec -p rake" #extra memory settings for resque workers
|
16
|
+
|
17
|
+
#the jexec file in script/ may look like:
|
18
|
+
|
19
|
+
#scriptdir=`dirname $0`
|
20
|
+
#
|
21
|
+
## Hack to get things working under capistrano (used for torquebox to get rake working, still needed?)
|
22
|
+
#if [ "$1" = "-j" ]; then
|
23
|
+
# shift
|
24
|
+
# export JRUBY_HOME=$1
|
25
|
+
# shift
|
26
|
+
#fi
|
27
|
+
#
|
28
|
+
#if [ "$1" = "-m" ]; then
|
29
|
+
# shift
|
30
|
+
# export JAVA_MEM="-Xmx2048m -Xms256m -XX:PermSize=1024m -XX:MaxPermSize=1024m"
|
31
|
+
# export JAVA_STACK=-Xss4096k
|
32
|
+
#fi
|
33
|
+
#
|
34
|
+
#export PATH=$scriptdir:/opt/jruby/bin:$PATH
|
35
|
+
#
|
36
|
+
## Configuration settings for all Rake Tasks and Resque Workers
|
37
|
+
#if [ "$1" = "-p" ]; then
|
38
|
+
# shift
|
39
|
+
# # Set Heap Space for Young/Eden GC: 512MB
|
40
|
+
# # Initial Heap size: 2GB
|
41
|
+
# # Max Heap size: 4GB
|
42
|
+
# # Use server JVM
|
43
|
+
# # PermGenSize: 64MB
|
44
|
+
# # Max PermGenSize: 128MB
|
45
|
+
# # Thread Stack Size: 1024k
|
46
|
+
# export JRUBY_OPTS="-J-Xmn512m -J-Xms2048m -J-Xmx4096m -J-server -J-XX:PermSize=64m -J-XX:MaxPermSize=128m -J-Xss1024k"
|
47
|
+
# echo "JRUBY_OPTS=${JRUBY_OPTS}"
|
48
|
+
# nohup $* & #cap task runs in background
|
49
|
+
#else
|
50
|
+
# exec $*
|
51
|
+
#fi
|
52
|
+
|
53
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
54
|
+
|
55
|
+
set :resque_worker_rake, nil # initialize variables, set in your deploy.rb
|
56
|
+
set :resque_applications, nil # initialize variables, set in your deploy.rb
|
57
|
+
|
58
|
+
def get_rake
|
59
|
+
fetch(:resque_worker_rake, fetch(:rake, "rake"))
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_worker_path
|
63
|
+
(ENV['application_path'].to_s.size > 0) ? ENV['application_path'] : current_path
|
64
|
+
end
|
65
|
+
|
66
|
+
namespace :resque do
|
67
|
+
desc "start a resque worker. optional arg: host=ip queue=name"
|
68
|
+
task :work, :roles => :resque do
|
69
|
+
default_run_options[:pty] = true
|
70
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
71
|
+
queue = ENV['queue'] || '*'
|
72
|
+
rake = get_rake
|
73
|
+
run("cd #{get_worker_path}; nohup #{rake} RAILS_ENV=#{stage} QUEUE=#{queue} resque:work >> log/resque_worker.log 2>&1", :hosts => hosts)
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Gracefully kill a worker. If the worker is working, it will finish before shutting down. arg: host=ip pid=pid"
|
77
|
+
task :quit_worker, :roles => :resque do
|
78
|
+
if ENV['host'].nil? || ENV['host'].empty? || ENV['pid'].nil? || ENV['pid'].empty?
|
79
|
+
puts 'You must enter the host and pid to kill..cap resque:quit_worker host=ip pid=pid'
|
80
|
+
else
|
81
|
+
#The kill command used to be done directly in the cap task, but since workers can now live in multiple apps, we need to send
|
82
|
+
#the correct signal based on the worker's platform which has to be done in the rake task."
|
83
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
84
|
+
run("cd #{get_worker_path}; nohup #{get_rake} RAILS_ENV=#{stage} resque:quit_worker pid=#{ENV['pid']}", :hosts => hosts)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Pause all workers in a single process. arg: host=ip pid=pid"
|
89
|
+
task :pause_worker, :roles => :resque do
|
90
|
+
if ENV['host'].nil? || ENV['host'].empty? || ENV['pid'].nil? || ENV['pid'].empty?
|
91
|
+
puts'You must enter the host and pid to kill..cap resque : pause_worker host=ip pid=pid'
|
92
|
+
else
|
93
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
94
|
+
run("kill -USR2 #{ENV['pid']}", :hosts => hosts)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "Continue all workers in a single process that have been paused. arg: host=ip pid=pid"
|
99
|
+
task :continue_worker, :roles => :resque do
|
100
|
+
if ENV['host'].nil? || ENV['host'].empty? || ENV['pid'].nil? || ENV['pid'].empty?
|
101
|
+
puts'You must enter the host and pid to kill..cap resque : continue_worker host=ip pid=pid'
|
102
|
+
else
|
103
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
104
|
+
run("kill -CONT #{ENV['pid']}", :hosts => hosts)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
desc "Gracefully kill all workers on all servers. If the worker is working, it will finish before shutting down."
|
109
|
+
task :quit_workers, :roles => :resque do
|
110
|
+
default_run_options[:pty] = true
|
111
|
+
rake = fetch(:rake, "rake")
|
112
|
+
run("cd #{get_worker_path}; #{rake} RAILS_ENV=#{stage} resque:quit_workers")
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "Kill a rogue worker. If the worker is working, it will not finish and the job will go to the Failed queue as a DirtyExit. arg: host=ip pid=pid"
|
116
|
+
task :kill_worker_with_impunity, :roles => :resque do
|
117
|
+
if ENV['host'].nil? || ENV['host'].empty? || ENV['pid'].nil? || ENV['pid'].empty?
|
118
|
+
puts'You must enter the host and pid to kill..cap resque : quit host=ip pid=pid'
|
119
|
+
else
|
120
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
121
|
+
run("kill -9 #{ENV['pid']}", :hosts => hosts)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
desc "Kill all rogue workers on all servers. If the worker is working, it will not finish and the job will go to the Failed queue as a DirtyExit."
|
126
|
+
task :kill_workers_with_impunity, :roles => :resque do
|
127
|
+
default_run_options[:pty] = true
|
128
|
+
rake = fetch(:rake, "rake")
|
129
|
+
run("cd #{get_worker_path}; #{rake} RAILS_ENV=#{stage} resque:kill_workers_with_impunity")
|
130
|
+
end
|
131
|
+
|
132
|
+
desc "start multiple resque workers. arg:count=x optional arg: host=ip queue=name"
|
133
|
+
task :workers, :roles => :resque do
|
134
|
+
default_run_options[:pty] = true
|
135
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
136
|
+
queue = ENV['queue'] ||'*'
|
137
|
+
count = ENV['count'] ||'1'
|
138
|
+
rake = get_rake
|
139
|
+
run("cd #{get_worker_path}; nohup #{rake} RAILS_ENV=#{stage} COUNT=#{count} QUEUE=#{queue} resque:work >> log/resque_worker.log 2>&1", :hosts => hosts)
|
140
|
+
end
|
141
|
+
|
142
|
+
desc "Restart all workers on all servers"
|
143
|
+
task :restart_workers, :roles => :resque do
|
144
|
+
default_run_options[:pty] = true
|
145
|
+
rake = fetch(:rake, "rake")
|
146
|
+
#pass the rake options to the rake task so the workers can be started with the options.
|
147
|
+
run("cd #{get_worker_path}; RAILS_ENV=#{stage} RAKE_WITH_OPTS='#{get_rake}'nohup #{rake} resque:restart_workers")
|
148
|
+
end
|
149
|
+
|
150
|
+
# ====================================
|
151
|
+
# ResqueScheduler TASKS
|
152
|
+
# ====================================
|
153
|
+
|
154
|
+
desc "start a resque worker. optional arg: host=ip queue=name"
|
155
|
+
task :scheduler, :roles => :resque do
|
156
|
+
default_run_options[:pty] = true
|
157
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
158
|
+
rake = fetch(:rake, "rake")
|
159
|
+
run("cd #{get_worker_path}; nohup #{rake} RAILS_ENV=#{stage} resque:scheduler", :hosts => hosts)
|
160
|
+
end
|
161
|
+
|
162
|
+
desc "Gracefully kill the scheduler on a server. arg: host=ip"
|
163
|
+
task :quit_scheduler, :roles => :resque do
|
164
|
+
if ENV['host'].nil? || ENV['host'].empty?
|
165
|
+
puts'You must enter the host to kill..cap resque:quit_scheduler host=ip pid=pid'
|
166
|
+
else
|
167
|
+
hosts = ENV['host'] || find_servers_for_task(current_task).collect { |s| s.host }
|
168
|
+
rake = fetch(:rake, "rake")
|
169
|
+
run("cd #{get_worker_path}; nohup #{rake} RAILS_ENV=#{stage} resque:quit_scheduler", :hosts => hosts)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
desc "Determine if the scheduler is running or not on a server"
|
174
|
+
task :scheduler_status, :roles => :resque do
|
175
|
+
hosts = ENV['hosts'].to_s.split(',') || find_servers_for_task(current_task).collect { |s| s.host }
|
176
|
+
|
177
|
+
status = nil
|
178
|
+
|
179
|
+
run("ps -eaf | grep resque | grep -v cap", :hosts => hosts) do |channel, stream, data|
|
180
|
+
status = (data =~ /resque:scheduler/) ? 'up' : 'down'
|
181
|
+
puts " ** [#{stream} :: #{channel[:host]}] resque:scheduler is #{status}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "resque_manager/engine"
|
2
|
+
require 'resque/server'
|
3
|
+
require 'resque_manager/overrides/resque/worker'
|
4
|
+
require 'resque_manager/overrides/resque/resque'
|
5
|
+
require 'resque_manager/overrides/resque/job'
|
6
|
+
require 'resque_manager/overrides/resque/failure/redis'
|
7
|
+
if Resque.respond_to? :schedule
|
8
|
+
require 'resque_scheduler/tasks'
|
9
|
+
require 'resque_manager/overrides/resque_scheduler/resque_scheduler'
|
10
|
+
end
|
11
|
+
require 'resque-status'
|
12
|
+
require 'resque_manager/overrides/resque_status/status'
|
13
|
+
require 'resque_manager/overrides/resque_status/chained_status'
|
14
|
+
require 'resque-cleaner'
|
15
|
+
|
16
|
+
Resque::Server.tabs << 'Statuses'
|
17
|
+
Resque::Server.tabs.delete 'Failed'
|
18
|
+
|
19
|
+
module ResqueManager
|
20
|
+
# Set this to a hash of all the different applications and deployment paths
|
21
|
+
# for those applications that have workers you want to manage.
|
22
|
+
# The different app do not have to be deployed to the same server.
|
23
|
+
# ex. {app1: 'www/var/rails/app1/current',
|
24
|
+
# app2: 'www/var/rails/app2/current'}
|
25
|
+
# There is no need to set this if all the workers live in the same app as the Resque Manager
|
26
|
+
# It will default to the current app's deploy path
|
27
|
+
mattr_accessor :applications
|
28
|
+
@@applicataions = nil
|
29
|
+
|
30
|
+
mattr_accessor :redis_config
|
31
|
+
@@redis_config = "SET TO RESQUE'S REDIS CONFIGURATION HASH"
|
32
|
+
|
33
|
+
# Optionally set this to when you want to expire the resque keys.
|
34
|
+
mattr_accessor :key_expiration
|
35
|
+
@@key_expiration = nil
|
36
|
+
|
37
|
+
# Optionally set this to determine whether to run inline or not.
|
38
|
+
mattr_accessor :inline
|
39
|
+
@@inline
|
40
|
+
|
41
|
+
def self.configure
|
42
|
+
yield self
|
43
|
+
Resque.redis = Redis.new(redis_config)
|
44
|
+
Resque::Plugins::Status::Hash.expire_in = key_expiration
|
45
|
+
Resque.inline = inline
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
namespace :resque do
|
2
|
+
|
3
|
+
desc "Start a Resque worker, each queue will create it's own worker in a separate thread"
|
4
|
+
task :work => :setup do
|
5
|
+
require 'resque'
|
6
|
+
|
7
|
+
worker = nil
|
8
|
+
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split('#').delete_if { |a| a.blank? }
|
9
|
+
threads = []
|
10
|
+
mqueue = queues.shift
|
11
|
+
# we are assuming the application has been deployed with a standard cap recipe.
|
12
|
+
base, version = Rails.root.to_s.split('/releases')
|
13
|
+
worker_path = base
|
14
|
+
# add current to the path to use the symlink used by a standard cap deploy
|
15
|
+
# unless the app is deployed to the "current" directory when using cap-git-deploy
|
16
|
+
worker_path += '/current' unless Rails.env.development? || worker_path =~ /current/
|
17
|
+
Thread.current[:queues] = mqueue
|
18
|
+
Thread.current[:path] = worker_path
|
19
|
+
mworker = Resque::Worker.new(mqueue)
|
20
|
+
mworker.verbose = true #ENV['LOGGING'] || ENV['VERBOSE']
|
21
|
+
mworker.very_verbose = true #ENV['VVERBOSE']
|
22
|
+
|
23
|
+
if ENV['PIDFILE']
|
24
|
+
File.open(ENV['PIDFILE'], 'w') { |f| f << mworker.pid }
|
25
|
+
end
|
26
|
+
|
27
|
+
queues.each do |queue|
|
28
|
+
threads << Thread.new do
|
29
|
+
begin
|
30
|
+
Thread.current[:queues] = queue
|
31
|
+
Thread.current[:path] = worker_path
|
32
|
+
worker = Resque::Worker.new(queue)
|
33
|
+
worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
|
34
|
+
worker.very_verbose = ENV['VVERBOSE']
|
35
|
+
rescue Resque::NoQueueError
|
36
|
+
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
|
37
|
+
end
|
38
|
+
|
39
|
+
worker.log "Starting worker #{worker}"
|
40
|
+
begin
|
41
|
+
worker.work(ENV['INTERVAL'] || 5) # interval, will block
|
42
|
+
rescue Exception => e
|
43
|
+
puts "********** e.message = " + e.message.inspect
|
44
|
+
Rails.logger.info "********** e.message = " + e.message.inspect
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
threads.each { |thread| thread.join(0.5) }
|
49
|
+
mworker.work(ENV['INTERVAL'] || 5) # interval, will block
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Restart all the workers"
|
53
|
+
task :restart_workers => :setup do
|
54
|
+
require 'resque'
|
55
|
+
pid = ''
|
56
|
+
queues = ''
|
57
|
+
local_ip = Resque.workers.first.local_ip rescue '';
|
58
|
+
rake = ENV['RAKE_WITH_OPTS'] || 'rake'
|
59
|
+
Resque.workers.sort_by { |w| w.to_s }.each do |worker|
|
60
|
+
if local_ip == worker.ip # only restart the workers that are on this server
|
61
|
+
if pid != worker.pid
|
62
|
+
if RUBY_PLATFORM =~ /java/
|
63
|
+
#jruby doesn't trap the -QUIT signal
|
64
|
+
#-TERM gracefully kills the main pid and does a -9 on the child if there is one.
|
65
|
+
#Since jruby doesn't fork a child, the main worker is gracefully killed.
|
66
|
+
system("kill -TERM #{worker.pid}")
|
67
|
+
else
|
68
|
+
system("kill -QUIT #{worker.pid}")
|
69
|
+
end
|
70
|
+
queues = worker.queues_in_pid.join('#')
|
71
|
+
Thread.new(queues) { |queue| system("nohup #{rake} RAILS_ENV=#{Rails.env} QUEUE=#{queue} resque:work") }
|
72
|
+
pid = worker.pid
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Gracefully kill a single worker. If the worker is working, it will finish before shutting down. arg: pid=pid
|
79
|
+
This used to be done directly in the cap task, but since workers can now live in multiple apps, we need to send
|
80
|
+
the correct signal based on the worker's platform."
|
81
|
+
task :quit_worker => :setup do
|
82
|
+
if RUBY_PLATFORM =~ /java/
|
83
|
+
#jruby doesn't trap the -QUIT signal
|
84
|
+
#-TERM gracefully kills the main pid and does a -9 on the child if there is one.
|
85
|
+
#Since jruby doesn't fork a child, the main worker is gracefully killed.
|
86
|
+
system("kill -TERM #{ENV['pid']}")
|
87
|
+
else
|
88
|
+
system("kill -QUIT #{ENV['pid']}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "Gracefully kill all the workers. If the worker is working, it will finish before shutting down."
|
93
|
+
task :quit_workers => :setup do
|
94
|
+
require 'resque'
|
95
|
+
pid = ''
|
96
|
+
local_ip = Resque.workers.first.local_ip
|
97
|
+
Resque.workers.sort_by { |w| w.to_s }.each do |worker|
|
98
|
+
if local_ip == worker.ip # only quit the workers that are on this server
|
99
|
+
if pid != worker.pid
|
100
|
+
if RUBY_PLATFORM =~ /java/
|
101
|
+
#jruby doesn't trap the -QUIT signal
|
102
|
+
#-TERM gracefully kills the main pid and does a -9 on the child if there is one.
|
103
|
+
#Since jruby doesn't fork a child, the main worker is gracefully killed.
|
104
|
+
system("kill -TERM #{worker.pid}")
|
105
|
+
else
|
106
|
+
system("kill -QUIT #{worker.pid}")
|
107
|
+
end
|
108
|
+
pid = worker.pid
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "Kill all rogue workers on all servers. If the worker is working, it will not finish and the job will go to the Failed queue as a DirtExit. arg: host=ip pid=pid"
|
115
|
+
task :kill_workers_with_impunity => :setup do
|
116
|
+
require 'resque'
|
117
|
+
pid = ''
|
118
|
+
local_ip = Resque.workers.first.local_ip
|
119
|
+
Resque.workers.sort_by { |w| w.to_s }.each do |worker|
|
120
|
+
if local_ip == worker.ip # only kill the pids that are on this server
|
121
|
+
if pid != worker.pid # only kill it once
|
122
|
+
`kill -9 #{worker.pid}`
|
123
|
+
pid = worker.pid
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| | |-- images
|
161
|
+
| | |-- javascripts
|
162
|
+
| | `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| |-- assets
|
177
|
+
| `-- tasks
|
178
|
+
|-- log
|
179
|
+
|-- public
|
180
|
+
|-- script
|
181
|
+
|-- test
|
182
|
+
| |-- fixtures
|
183
|
+
| |-- functional
|
184
|
+
| |-- integration
|
185
|
+
| |-- performance
|
186
|
+
| `-- unit
|
187
|
+
|-- tmp
|
188
|
+
| `-- cache
|
189
|
+
| `-- assets
|
190
|
+
`-- vendor
|
191
|
+
|-- assets
|
192
|
+
| |-- javascripts
|
193
|
+
| `-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|