问题描述:

Edit: Ok I've posted my code on this repository here https://github.com/willnance/doctor-self-study

Hoping someone can take a look at it. I'm at wits end. I've looked at every single example I can find and cannot figure this out. No matter how I change the parameters for enqueue_at( the error doesn't change. If I don't pass any argument and try to enqueue_at( then I get wrong number of arguments 0 for 1 at the same line -- the declaration of the perform method of my job. Absolutely baffling.

There's not a single post online about this specific error.

furthermore if anyone has any recommendations about how to debug this that would be awesome. I'm running netbeans 7.1 IDE with the open source ruby / rails plugin on windows and haven't been able to find a debugging method.

end edit.

I've set up a rails app with resque_scheduler. I intend to deploy it to heroku soon (using that nifty autoscaling code that floats about on the internet) but I'm trying to iron out the kinks locally. i opened up the resque-web interface and noticed that I had 10 failed jobs ( -_- )

All of them have the exact same error message. I cant even really wrap my head around what's going wrong. Its looking for doctor_self_study_development.id , which is basically the app name, the environment and .id. I really don't understand why this is happening.

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'

So seeing that the error is happening in the perform method, here is the job class thats doing the lifting here:

#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

and finally here is the model with the callback on_create that triggers 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

Here are the resque.rake and 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:[email protected]: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)

I'd appreciate any explanation of what's going on here and some pointers on how to fix it.

相关阅读:
Top