我有一个用户对象,我从 twitter/facebook 获取用户数据,然后点击保存,最后将和user_id
发送avatar_url
到Resque.enqueue
.
self.save!
Resque.enqueue(AvatarPull, {user_id: self.id, url: user[:avatar] }) if user[:avatar] and self.avatar.blank?
然后在self.perform
我只是使用 find 通过 id 获取用户然后设置头像然后保存。
@queue = :paperclip
def self.perform(options={})
user = User.find(options[:user_id])
user.avatar = URI.parse(options[:url].sub("_normal", ""))
user.save!
end
问题是我因为没有按 id 找到用户而收到此错误
(Job{paperclip} | AvatarPull | [{"user_id"=>"51191a5e0eae9cfccf000006", "url"=>"http://source"}]) failed: #<Mongoid::Errors::InvalidFind:
Problem:
Calling Document.find with nil is invalid.
Summary:
Document.find expects the parameters to be 1 or more ids, and will return a single document if 1 id is provided, otherwise an array of documents if multiple ids are provided.
Resolution:
Most likely this is caused by passing parameters directly through to the find, and the parameter either is not present or the key from which it is accessed is incorrect.>
我认为这是因为进入队列所花费的时间少于将记录保存在数据库中所花费的时间。有没有办法解决这个问题,可能会增加延迟或者还有其他什么?