简体   繁体   中英

How to write task which run multiple tasks with args?

I would like to run task for each model like below:

task all: :environment do
  resources = [ Question,
                Answer,
                Link,
                Event,
                PastEvent,
                Review ]
  resources.each do |resource|
    #Rake::Task["tire:import CLASS=#{resource} FORCE=true"].execute
    system "rake environment tire:import CLASS='#{resource}' FORCE=true"
  end
end

Is better way to use system for that?

You can use Rake::Task["<your_task>"].invoke(<params>) .

Eg: Rake::Task["db:migrate"].invoke .

invoke runs the dependencies as well unlike execute . If the task has already been invoked, you'll need to do use reenable ie Rake::Task["<your_task>"].reenable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM