This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

How do I run a rake task from Capistrano

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 0.88 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. run("cd #{deploy_to}/current && /usr/bin/env rake `<task_name>` RAILS_ENV=production")`
  2.        
  3. namespace :rake do  
  4.   desc "Run a task on a remote server."  
  5.   # run like: cap staging rake:invoke task=a_certain_task  
  6.   task :invoke do  
  7.     run("cd #{deploy_to}/current; /usr/bin/env rake #{ENV['task']} RAILS_ENV=#{rails_env}")  
  8.   end  
  9. end
  10.        
  11. cap staging rake:invoke task=rebuild_table_abc
  12.        
  13. def run_rake(task, options={}, &block)
  14.   command = "cd #{latest_release} && /usr/bin/env bundle exec rake #{task}"
  15.   run(command, options, &block)
  16. end
  17.        
  18. def rake(cmd, options={}, &block)
  19.   command = "cd #{current_release} && /usr/bin/env bundle exec rake #{cmd} RAILS_ENV=#{rails_env}"
  20.   run(command, options, &block)
  21. end
  22.        
  23. rake 'app:compile:jammit'
  24.        
  25. run("cd #{release_path}/current && /usr/bin/rake <rake_task_name>", :env => {'RAILS_ENV' => rails_env})
  26.        
  27. Rake::Task["task:name"].invoke
clone this paste RAW Paste Data