编辑:好的,我已经在此存储库上发布了我的代码https://github.com/willnance/doctor-self-study
希望有人可以看看。我无计可施。我已经查看了我能找到的每一个示例,但无法弄清楚这一点。无论我如何更改enqueue_at(
错误的参数都不会改变。如果我不传递任何参数并尝试传递,enqueue_at(
那么我会 wrong number of arguments 0 for 1
在同一行 - 声明perform
我的工作方法。绝对莫名其妙。
网上没有一篇关于这个特定错误的帖子。
此外,如果有人对如何调试它有任何建议,那就太棒了。我在 Windows 上使用开源 ruby / rails 插件运行 netbeans 7.1 IDE,但找不到调试方法。
结束编辑。
我已经使用 resque_scheduler 设置了一个 rails 应用程序。我打算很快将它部署到heroku(使用漂浮在互联网上的漂亮的自动缩放代码),但我正试图在本地解决问题。我打开了 resque-web 界面,发现我有 10 个失败的工作( - _ - )
它们都有完全相同的错误消息。我什至无法真正解决问题所在。它正在寻找 doctor_self_study_development.id
,这基本上是应用程序名称,环境,.id.
我真的不明白为什么会这样。
Worker
PCNAME-HP:12188 on READY_QUEUE at just now Retry or Remove
Class
SchedulerJob
Arguments
{"id"=>40}
Exception
ActiveRecord::StatementInvalid
Error
Mysql2::Error: Table 'doctor self study_development.id' doesn't exist: SHOW FULL FIELDS FROM `id`
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:257:in `execute_and_free'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:424:in `columns'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/schema_cache.rb:16:in `yield'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/schema_cache.rb:16:in `default'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/schema_cache.rb:16:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:56:in `yield'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:56:in `default'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:56:in `block in build_from_hash'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `map'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `build_from_hash'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:13:in `block in build_from_hash'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `map'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/predicate_builder.rb:4:in `build_from_hash'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/query_methods.rb:327:in `build_where'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/query_methods.rb:136:in `where'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/relation/finder_methods.rb:264:in `find_by_attributes'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
C:/Users/Will Nance/Dropbox/Eclipse/Ruby on Rails Development/sample Heroku/app/jobs/scheduler_job.rb:8:in `perform'
所以看到错误发生在 perform 方法中,这里是在这里进行提升的作业类:
#ALL jobs and models must extend the Autoscaling module for cheap Heroku deployment
require 'heroku_resque_auto_scale'
class SchedulerJob
extend HerokuAutoScaler::AutoScaling
@queue = :ready_queue
def self.perform(id)
@assignment=Assignment.find_by_id(id)
@assignment.sendAlertEmail
end
end
最后是带有on_create
触发 enqueue_at()的回调的模型
require "scheduler_job"
#ALL jobs and models must extend the Autoscaling module for cheap Heroku deployment
require 'heroku_resque_auto_scale'
class Assignment ActiveRecord::Base extend HerokuAutoScaler::AutoScaling
belongs_to :user
belongs_to :question
attr_accessible :title, :body, :user_id, :question_id , :response , :correct
after_create :queue_assignments
before_destroy :remove_from_queue
def grade
self.correct = (response == self.question.solution) unless response == nil
end
def queue_assignments
Resque.enqueue_at(self.question.schedule , SchedulerJob , :id => self.id)
end
def remove_from_queue
Resque.remove_delayed(SchedulerJob, :id => self.id)
end
def sendAlertEmail
QuestionMailer.question(self)
end
def as_json(options={})
{
:correct => correct,
:created_at => created_at,
:id => id,
:question_id => question_id,
:response => response ,
:updated_at => updated_at,
:user_id => user_id,
:question => self.question
}
end
end
这里是resque.rake
和resque.rb
resque.rake
require 'resque/tasks'
require 'resque_scheduler/tasks'
require 'resque_scheduler/server'
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
task "resque:scheduler_setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
resque.rb
require 'resque_scheduler'
require 'resque/server'
ENV["REDISTOGO_URL"] ||= "redis://redistogo:f95d214230c8ec72a902bbd2b519dbe3@spinyfin.redistogo.com:9192/"
require 'resque'
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
我很感激对这里发生的事情的任何解释以及有关如何解决它的一些指示。