Ruby on rails Resque Worker:Worker中不可用的对象和方法
我的web应用程序中有以下工作程序Ruby on rails Resque Worker:Worker中不可用的对象和方法,ruby-on-rails,ruby,resque,resque-scheduler,Ruby On Rails,Ruby,Resque,Resque Scheduler,我的web应用程序中有以下工作程序 class TweetSender @queue = :tweets_queue def self.perform(tweet_id) message = Tweet.where(:status_id => 0).order(:created_at, :id).limit(1) message.update_attribute(status_id = 1)
class TweetSender
@queue = :tweets_queue
def self.perform(tweet_id)
message = Tweet.where(:status_id => 0).order(:created_at, :id).limit(1)
message.update_attribute(status_id = 1)
$client.update(message.text)
end
end
它由以下resque调度器tweet_scheduler.yml进行调度
tweet_发送者:
cron: "0 20 * * * Europe/Stockholm"
class: "TweetSender"
queue: tweets_queue
args: tweet_id
description: "This job sends daily tweets from the content db"
由他定义的resque.rake
require 'resque/tasks'
require 'resque/scheduler/tasks'
task 'resque:setup' => :environment
namespace :resque do
task :setup do
require 'resque'
end
task :setup_schedule => :setup do
require 'resque-scheduler'
Resque.schedule = YAML.load_file('tweet_schedule.yml')
require 'jobs'
end
task :scheduler => :setup_schedule
end
在resque web界面中,我得到以下错误
Exception
NoMethodError
Error
undefined method `update_attribute' for #<Tweet::ActiveRecord_Relation:0x839ca814>
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missing'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:99:in `method_missing'
/home/jan/Documents/social/app/jobs/tweet_sender.rb:6:in `perform'
并获取以下错误:
Exception
NoMethodError
Error
undefined method `status_id=' for #<Tweet::ActiveRecord_Relation:0x83195bf8>
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missing'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:99:in `method_missing'
/home/jan/Documents/social/app/jobs/tweet_sender.rb:6:in `perform'
异常
命名者
错误
未定义的方法“status\u id=”用于#
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active\u record/relation/delegation.rb:136:在“方法”中
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active\u record/relation/delegation.rb:99:in'method\u missing'
/home/jan/Documents/social/app/jobs/tweet_sender.rb:6:in'perform'
为什么我的方法和标准rails方法在我的工作人员中不可用?是否需要在某个地方显式地要求它们?返回ActiveRecord::Relation
的实例
您真正想要的是Tweet
model的一个实例
使用:
谢谢,这很有道理。尽管nil:NilClass/home/jan/Documents/social/app/jobs/tweet\u sender.rb:6:inperform''现在它甚至无法识别该类,但我仍然得到了错误。有什么想法吗?@Jan这意味着
首先
返回了您nil
,这意味着没有满足您的查询条件的结果。@Andreydeniko您是对的,我的数据库中没有相应的条目!谢谢你,火箭已经被弃用了,请不要在2017年回答问题时使用它们:)让大家学习。而不是应该更新代码的晦涩的初学者不友好评论:message=Tweet.where(status\u id:0)。order(:created\u at,:id)。first
Exception
NoMethodError
Error
undefined method `status_id=' for #<Tweet::ActiveRecord_Relation:0x83195bf8>
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missing'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:99:in `method_missing'
/home/jan/Documents/social/app/jobs/tweet_sender.rb:6:in `perform'
message = Tweet.where(status_id: 0).order(:created_at, :id).first