简体   繁体   中英

how to build a rake task

I'd like to learn how to build a rake task for my rails 3 app that does two things.

  1. Pushes assets to the CDN
  2. Deploys to heroku

Commands for the above steps:

 rake cache:s3
 heroku jammit:deploy --app #{app}

Here's what I have /lib/tasks/deployer.rake

task :deployit do
  puts '=== Storing assets on s3 ==='
  run "rake cache:s3"
  puts '=== Deploying to Heroku ==='
  run "heroku jammit:deploy --app #{app}"
end

def run(cmd)
  shell cmd
  if $?.exitstatus == 0
    display "[OK]"
  else
    display "[FAIL]"
  end
end

But that errors with 'undefined method `shell' for main:Object'

Suggestions on how to make this work? Should this be a task or something else?

Thanks

The first task is another rake task, which will run if it is a dependency of the :deployit task. Your current code would loads rake twice.

If you use system like Arun suggested you would get:

task :deployit => 'cache:s3' do
  puts '=== Deploying to Heroku ==='
  system "heroku jammit:deploy --app #{app}"
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM