Capistrano: Calling tasks from other tasks
Posted: May 1, 2009 Filed under: Computers, Rails Leave a comment »I wrote a new capistrano task for deploying a rails app the other day that would totally reset the old deployed database and give me a fresh new one with fixtures pre-loaded. This is useful for deploying different branches to the same location on a server. However the lack of proper capistrano documentation let to some wasted time figuring out how to invoke previously defined tasks from a new task. Most of them are just simple methods you can call, but to call the task deploy:migrations is a little more complex because it’s really a task called migrations in the deploy namespace.
So for my new “super deploy” task, deploy.rb looks something like this:
task :drop_db
run "cd #{deploy_to}; rake db:drop"
end
task :create_db
run "cd #{deploy_to}; rake db:drop"
end
task :super_deploy
drop_db
namespace :deploy
migrations
end
create_db
end
Pretty simple but I got hung up it for a few minutes. So there you go.