Invoking a Rake Multitask in a loop

I am running selenium tests that I launch using a rake task. Recently I wanted to run a bunch on them concurrently every so often. The problem I ran into immediately, was that the tasks were only executed once. It turns out that, when calling a multitask multiple times, you not only have to .reenable the multitask but also have to .reenable each pre-requisite task. This is easily achievable using the following code:

multitask :task_group => [:task1, :task2]

task :run_in_loop do
  # run 10 times
  10.times do
    Rake:Task[:task_group].invoke
    Rake:Task[:task_group].reenable
    Rake:Task[:task_group].prerequisite_tasks.each do |task|
      task.reenable
    end
    #sleep for 10 mins (optional)
    sleep(10*60)
  end
end

Leave a Reply

Your email address will not be published. Required fields are marked *