如何运行所有rake任务? [英] How do I run all rake tasks?

查看:161
本文介绍了如何运行所有rake任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚安装了gem https://github.com/javan/whenever 运行我的耙子任务,这是nokogiri / feedzilla相关的抓取任务。

Have just installed whenever gem https://github.com/javan/whenever to run my rake tasks, which are nokogiri / feedzilla dependent scraping tasks.

例如我的任务称为grab_bbc,grab_guardian等

eg my tasks are called grab_bbc, grab_guardian etc

我的问题 - 当我更新我的网站,我继续添加更多的任务给scheduler.rake。

My question - as I update my site, I keep add more tasks to scheduler.rake.

我应该在我的config / schedule.rb写什么,使所有rake任务运行,无论他们叫什么?

What should I write in my config/schedule.rb to make all rake tasks run, no matter what they are called?

会是这样的吗?

    every 12.hours do
        rake:task.each do |task|
            runner task
        end 
    end

使用RoR 4.

推荐答案

为每个刮削任务编写单独的rake任务。然后写一个聚合任务来运行所有这些刮擦耙子任务。

write separate rake tasks for each scraping tasks. then write a aggregated task to run all those scraping rake tasks.

desc "scrape nytimes"
task :scrape_nytimes do
  # scraping method
end

desc "scrape guardian"
task :scrape_guardian do
  # scraping method
end

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

然后调用rake任务为

then call the rake task as

rake scrape

这篇关于如何运行所有rake任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆