你能从rakefile(scheduler.rake)调用一个类方法吗?
我正在使用Heroku Scheduler附加组件并编写了一个调用类方法的任务,但是当我运行'heroku run rake auto_start_games'时收到错误
Connecting to database specified by DATABASE_URL
rake aborted!
compared with non class/module
这是我的任务代码:
task :auto_start_games => :environment do
all_Active_Games = Game.where(:game_active => 1)
not_flag = all_Active_Games > 0
started_games = []
unless all_Active_Games.length == 0
all_Active_Games.each do |x|
if x.players >= 2
x.winning_structure = 1 if x.players < 3
Comments.gameStartComment(x.id)
Game.gameHasStartedPush(x)
x.game_initialized = 1
x.was_recently_initiated = 1
started_games << x.id
else
Game.addDaytoStartandEnd(x.id)
Comment.gamePostponedComment(x.id)
end
end
end
puts "started games #{started_games}"
end
答案 0 :(得分:1)
当您调用Rake时,您可以将--trace
标志传递给它。这应该给你一个回溯,我怀疑它会告诉你错误是在行not_flag = all_Active_Games > 0
,因为all_Active_Games
是一个ActiveRecord关系,但你试图将它与整数0进行比较基本上,你有一个类型错误。在静态语言中,这甚至都不会编译。
也可以修复缩进,选择更具描述性的变量名称(x
- &gt; game
)