Args没有被传递给Rake任务

时间:2011-02-23 16:21:38

标签: ruby-on-rails arguments rake task

我有一个rake任务接受一个参数:scope(下面)。 我将rake任务称为:

rake podcast:generate_inventory["new"]

此任务用于完美地传递:scope arg,但是,我今天注意到arg不再被传递。有谁知道为什么会这样?

namespace :podcast do

  task :itunes_top_300, [:scope] => :environment do |t,args|
    Podcast.podcast_logger.info("BEGIN: #{Time.now}")
    if args[:scope] == "new"
      Podcast.podcast_logger.info("NEW PODCASTS ONLY")
    end
    Podcast.itunes_top_rss
  end

  task :itunes_genres_top_300 => :itunes_top_300 do
    Podcast.itunes_genre_rss
  end

  task :site_and_feed_discovery, [:scope] => :itunes_genres_top_300 do |t,args|
    if args[:scope] == "new"
      Podcast.site_and_feed_discovery(:new_podcasts_only => true)
    else
      Podcast.site_and_feed_discovery
    end
  end

  task :social_discovery, [:scope] => :site_and_feed_discovery do |t,args|
    if args[:scope] == "new"
      Podcast.social_discovery(:new_podcasts_only => true)
    else
      Podcast.social_discovery
    end
  end

  task :fetch_episodes => :social_discovery do |t,args|
    Episode.episode_logger.info("BEGIN: #{Time.now}")
    Podcast.fetch_episodes
    Episode.episode_logger.info("END: #{Time.now}")
  end

  task :generate_inventory => :fetch_episodes do |t,args|
    Podcast.podcast_logger.info("Successful Rake")
    Podcast.podcast_logger.info("END #{Time.now}")
    Rake::Task['maintenance:daily'].invoke
  end
end

1 个答案:

答案 0 :(得分:1)

您似乎错过了[:scope]定义中的task :generate_inventory位。我怀疑补充一点就是照顾好一切。

希望有所帮助!