0

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)
padi
  • 787
  • 7
  • 11

2 Answers2

0

Try doing

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...'
    system 'git push heroku master'
  end

  task :migrate do
    puts 'Running database migrations ...'
    system 'heroku run rake db:migrate'
  end

  task :restart do
    puts 'Restarting app servers ...'
    system 'heroku restart'
  end
end

So basically just replace exec calls with system calls.

dextrey
  • 815
  • 7
  • 9
  • Thanks for the help. I figured it out on my own. `system` works, but backticks ` are what I wanted after all. :) – padi Sep 02 '12 at 07:03
0

I should use backticks (`) instead of the exec ruby command. Here's what the code should like for the rake deploy_production to work:

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...'
    `git push heroku master`
  end

  task :migrate do
    puts 'Running database migrations ...'
    `heroku run rake db:migrate`
  end

  task :restart do
    puts 'Restarting app servers ...'
    `heroku restart`
  end
end

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 system in ruby is because of the slight advantage discussed here: Ruby, Difference between exec, system and %x() or Backticks

Community
  • 1
  • 1
padi
  • 787
  • 7
  • 11