开发者

Clean up task when combining multiple tasks in Rake

I have a build task in rake defined with the following dependencies:

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

The first task "solr:start" starts the Solr Indexing server. Now, if the build fails (may be in spec tests fail), the "solr:stop" task is not executed. And the server is not stopped.

Is there any way to specify a clean-up task or a task that always runs even if one of the dependen开发者_C百科t tasks fail? In my case, to always ensure that "solr:stop" executes...


You just need use the ensure system of Ruby

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜