Defining tasks with parallel prerequisites
Describing rake tasks that depend on other tasks that should be executed in parallel is actually a straightforward, solvable problem. Just define your tasks with a multitask
method instead of the task
method, as shown in the following code snippet, and that's it:
multitask :setup => [:install_ruby, :install_nginx, :install_rails] do puts "The build is completed" end
In this example, the tasks install_ruby
, install_nginx
, and install_rails
will be executed in parallel before the action of the setup
task. This means that for each dependent task, a Ruby thread will be created and they will be run at the same time. The setup
task will wait for the threads until they are finished.
Check out the following Rakefile
that will be used to verify the previously mentioned statements:
task :task1 do puts 'Action of task 1' end task :task2 do puts 'Action of task 2' end multitask :task3 => [:task1, :task2] do puts 'Action of task 3' end
Now, open the...