参数未传递给 Rake 任务

发布于 2024-10-19 06:11:12 字数 1449 浏览 1 评论 0原文

我有一个接受参数 :scope (如下)的 rake 任务。 我这样称呼 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

I have a rake task that accepts an argument, :scope (below).
I call the rake task like this:

rake podcast:generate_inventory["new"]

This task used to pass the :scope arg perfectly, however, I noticed today that the arg is no longer being passed. Does anyone have any idea why this is happening?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2024-10-26 06:11:12

看起来您在 task :generate_inventory 定义中缺少 [:scope] 位。我怀疑将其添加回来会解决所有问题。

希望有帮助!

Looks like you're missing the [:scope] bit in your definition of task :generate_inventory. I suspect adding that back in will take care of everything.

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文