5

I'm trying to run a list of rake task within a shared :namespace following this post: How do I run all rake tasks?.

But its not working.

Recommendation per post

desc "perform all scraping"
task :scrape do
  Rake::Task[:scrape_nytimes].execute 
  Rake::Task[:scrape_guardian].execute 
end

The difference in my case is that all rake tasks are in a namespace.

Rake tasks

namespace :get_ready do
  task check_weather: :environment do
    p 1
  end
  task make_lunch: :environment do
    p 2
  end
  task start_car: :environment do
    p 3
  end
end

Attempting to create a rake task that runs all rake tasks as below.

desc "Run all tasks"
task run_all: :environment do
  Rake::Task[:check_weather].execute 
  Rake::Task[:make_lunch].execute    
  Rake::Task[:start_car].execute       
end 

And then running with rake run_all or rake get_ready. The below variations I tried also didn't work.

  • Rake::Task[run_all:check_weather].execute
  • Rake::Task[:run_all, :check_weather].execute

Does anyone have experience running a batch of rake tasks in a shared namespace and knows how to do this?

Community
  • 1
  • 1
tim_xyz
  • 11,573
  • 17
  • 52
  • 97

2 Answers2

5

It should be:

desc "Run all tasks"
task run_all: :environment do
  Rake::Task['get_ready:check_weather'].execute 
  Rake::Task['get_ready:make_lunch'].execute    
  Rake::Task['get_ready:start_car'].execute       
end

The namespace is get_ready and check_weather, make_lunch, start_car are task in that namespace.

More elegant solution is:

desc "Run all tasks"
task run_all_elegantly: [:environment, 'get_ready:check_weather', 'get_ready:make_lunch', 'get_ready:start_car']
Dmitry Shvetsov
  • 651
  • 10
  • 19
0

Every noticed the output of rails -T or in your case rails -T get_ready ? It shows every command, and the description as comment, so you could pipe the output and execute it with bash:

(rails -T deploy) | /bin/bash

So there is no need to make an extra task if you want to execute all tasks.

Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27