Rake 相当于 make -j (--jobs)

Rake equivalent of make -j (--jobs)

make 命令允许 -j (--jobs) 选项记录如下:

-j [jobs], --jobs[=jobs]
     Specifies the number of jobs (commands) to run simultaneously.  If there is more than one -j  option,
     the  last  one  is effective.  If the -j option is given without an argument, make will not limit the
     number of jobs that can run simultaneously.

在这个连手机都有多核 and/or 处理器的时代,我希望我的构建系统能够处理多线程处理。

设置 rake 的最佳方法是什么,这样我就可以确保最多 3 个任务始终 运行?

有一篇关于 rake MultiTask 的博客 post,但它支持 -j 参数作为 -m 进行并行化。

是的,rake 允许作业并行 运行。要设置并行级别,请使用 -j 开关。来自 rake --help:

-j, --jobs [NUMBER] Specifies the maximum number of tasks to execute in parallel. (default is number of CPU cores + 4)

但是,作业本身必须写成多任务,而不是任务。所以不要像这样定义任务:

namespace :mynamespace  do
  desc "description"
  task task_name: :environment do
    your_code
  end
end

使用多任务:

namespace :mynamespace  do
  desc "description"
  multitask task_name: :environment do
    your_code
  end
end