如何构建 rake 任务

发布于 2024-11-30 07:37:23 字数 647 浏览 0 评论 0原文

我想了解如何为我的 Rails 3 应用程序构建一个有两件事的 rake 任务。

  1. 将资产推送到 CDN
  2. 部署到 heroku

上述步骤的命令:

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

这是我的 /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

但出现 'undefined method `shell' for main:Object' 的错误

建议如何进行这项工作?这应该是一项任务还是其他什么?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳根太软 2024-12-07 07:37:23

第一个任务是另一个 rake 任务,如果它是 :deployit 任务的依赖项,它将运行。您当前的代码将加载 rake 两次。

如果您使用 Arun 建议的系统,您将得到:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文