我的网络应用中有以下工作人员
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-scheduler tweet_scheduler.yml进行调整
tweet_sender:
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'
我尝试使用update_atttribute方法实现tweet_sender.rb,如下所示:
class TweetSender
@queue = :tweets_queue
def self.perform(tweet_id)
message = Tweet.where(:status_id => 0).order(:created_at, :id).limit(1)
message.status_id = 1
message.save
$client.update(message.text)
end
end
并得到以下错误:
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'
为什么我的方法和标准rails方法在我的工作人员中没有?我是否需要在某处明确要求它们?