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
精彩评论