参数未传递给 Rake 任务
我有一个接受参数 :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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您在
task :generate_inventory
定义中缺少[:scope]
位。我怀疑将其添加回来会解决所有问题。希望有帮助!
Looks like you're missing the
[:scope]
bit in your definition oftask :generate_inventory
. I suspect adding that back in will take care of everything.Hope that helps!