I’ve seen from this (http://stackoverflow.com/questions/1890709/combining-many-rake-tasks-into-one-rake-task) that you can combine rake tasks like this:
desc 'This rebuilds development db'
task :rebuild_dev => ["db:drop", "db:create", "db:migrate", "db:load"]
However when I try doing that to my local app to combine relatively simple rake tasks, each only running shell commands, it seems that it only executes whatever is the first in the array ['heroku:push', 'heroku:migrate', 'heroku:restart'].
Here’s the code:
desc 'Push to heroku production, db:migrate, and restart app'
task :deploy_production => ['heroku:push', 'heroku:migrate', 'heroku:restart']
namespace :heroku do
task :push do
puts 'Deploying app to Heroku...'
exec 'git push heroku master'
end
task :migrate do
puts 'Running database migrations ...'
exec 'heroku run rake db:migrate'
end
task :restart do
puts 'Restarting app servers ...'
exec 'heroku restart'
end
end
and by the way, in case you need it, here’s the version of rake:
$ gem list | grep rake
rake (0.9.2.2)
I should use backticks (`) instead of the
execruby command. Here’s what the code should like for therake deploy_productionto work:I had problems posting it immediately because I am new to stackoverflow, and I can’t post an answer immediately to my own question.
The reason I prefer backticks over
systemin ruby is because of the slight advantage discussed here: Ruby, Difference between exec, system and %x() or Backticks