I have a ruby script from which I want to launch 4 rake tasks to run in parallel.
How do I do this? I think I'll need to Fork and detach a process but I need the exact syntax.
It's better if you let Rake handle the parallelism. You can do that using "multitask." Inside the Rakefile:
desc "Start everything."
multitask :start => [ 'mongodb:start', 'haystack:start' ]
Background and source.
Otherwise, presuming you are doing this from outside the Rakefile, you could use horrid code like this, which would not throw exceptions as you might expect, and could easily fail in a number of ways:
require 'rake'
load 'Rakefile'
def invoke(name)
Thread.new do
puts Rake::application[name].invoke
end
end
invoke :make_coffee
invoke :boil_eggs
invoke :empty_trash
(so don't do that)
use https://github.com/grosser/parallel
Parallel.each(data, :in_processes => 4) { |x| ruby_function(x) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With