Created
May 18, 2010 10:42
-
-
Save danieljohnmorris/404864 to your computer and use it in GitHub Desktop.
r3 app tpl - load resque in a r3 friendly way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage (in app dir): | |
# rake rails:template LOCATION=http://gist.github.com/404864.txt | |
gem 'redis', '1.0.7' # bugfix for "uninitialized constant Redis::Client::ALIASES" | |
gem 'resque' | |
gem 'resque-scheduler' # non-blocking cron-alternative daemon | |
file "script/install_redis", <<-CODE | |
#!/bin/bash | |
git clone git://github.com/defunkt/resque.git vendor/resque | |
cd vendor/resque/ | |
rake redis:install dtach:install | |
cd ../../ | |
CODE | |
file "script/start_redis", <<-CODE | |
#!/bin/bash | |
cd vendor/resque/ | |
rake redis:start | |
CODE | |
file "script/start_workers", <<-CODE | |
queue="*" && [[ -z "$1" ]] && queue="$1" | |
COUNT=5 QUEUE=$queue rake resque:workers & | |
CODE | |
run "chmod 755 script/*" | |
if yes?("Do you want to install redis?") | |
run "script/install_redis" | |
end | |
initializer "resque.rb", <<-CODE | |
require 'resque' | |
CODE | |
rakefile "resque.rake", <<-TASK | |
task "resque:setup" => :environment | |
TASK | |
if yes?("Do you want to insert into Rakefile?") | |
# run "# Load resque tasks in Rakefile" | |
# load resque rake tasks | |
rakefile_contents = File.readlines 'Rakefile' | |
File.open('Rakefile', 'w') do |rakefile_out| | |
rakefile_out.write rakefile_contents[0..-3].join | |
rakefile_out.puts "" | |
rakefile_out.puts "require 'resque/tasks'" # inject resque tasks line | |
rakefile_out.puts "" | |
rakefile_out.write rakefile_contents[-2..-1].join | |
end | |
end | |
if yes?("Do you want to append to README?") | |
# run "# add redis & resque sections to README" | |
# add useful instructions redis & resque worker commands to app's README | |
File.open('README', 'a') do |f| f.write <<-TXT | |
== Redis | |
=== Install/First-run: | |
./script/install_redis | |
=== Start: | |
./script/start_redis | |
(ctrl-\ to detach) | |
== Resque | |
=== Start web interface: | |
./resque-web | |
=== Start pool of workers - all queues: | |
COUNT=5 QUEUE=* rake resque:workers | |
(ctrl-x to end) | |
=== Start pool of workers as background process - all queues: | |
COUNT=5 QUEUE=* rake resque:workers & | |
=== Start pool of workers - specific queue: | |
COUNT=5 QUEUE=some_important_queue rake resque:workers & | |
TXT | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment