简体   繁体   English

针对特定环境调用耙任务

[英]Invoking rake task for specific environment

Hello I'm writing a deploy script(rake task) for my mini project. 您好,我正在为我的小型项目编写部署脚本(rake任务)。 And I have this part when I invoke the db seed : 当我调用db种子时,我有这部分:

Rake::Task['db:seed'].invoke

And also compiling assets : 并编译资产:

Rake::Task['assets:precompile'].invoke

So I was wondering is there a way to invoke these tasks in production environment like you would do from a console like this : 所以我想知道是否可以像在这样的控制台中那样在生产环境中调用这些任务:

RAILS_ENV=production rake db:seed

In Rails, you can do as : 在Rails中,您可以执行以下操作:

[arup@app (master)]$ rails g task my_namespace my_task1
      create  lib/tasks/my_namespace.rake
[arup@app (master)]$ cat lib/tasks/my_namespace.rake
namespace :my_namespace do
  desc "TODO"
  task my_task1: :environment do
  end
end
[arup@app (master)]$

Now see the Rakefile is ready for you. 现在看到Rakefile已准备就绪。

Just open the Rakefile you just created, and define your tasks. 只需打开您刚刚创建的Rakefile ,然后定义您的任务即可。

namespace :my_namespace do
  task my_task1: :environment do
    Rake::Task['db:seed'].invoke
    Rake::Task['assets:precompile'].invoke
  end
end

Hints is 2.10 Custom Rake Tasks . 提示是2.10自定义耙任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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