繁体   English   中英

在Rake中合并多个任务时清理任务

[英]Clean up task when combining multiple tasks in Rake

我在rake中定义了一个构建任务,具有以下依赖关系:

desc 'Builds the App'
task :rebuild_dev => ["solr:start", "db:drop", "db:create", "db:migrate", "spec", "solr:stop"]

第一个任务“ solr:start”启动Solr索引服务器。 现在,如果构建失败(可能在规格测试中失败),则不会执行“ solr:stop”任务。 并且服务器没有停止。

有什么方法可以指定清理任务或即使相关任务之一失败也始终运行的任务? 就我而言,要始终确保执行“ solr:stop” ...

您只需要使用Ruby的suresure系统

desc "Builds the App"
task :rebuild_dev do
  begin
    ["solr:start", "db:drop", "db:create", "db:migrate", "spec"].each do |t|
      Rake::Task[t].execute
    end
  ensure
    Rake::Task["solr:stop"].execute
  end
end

暂无
暂无

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

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