A worker that was working a few days ago has ceased to work for some reason.
The resque log reports an exception of Mongo::OperationFailure
with the errorinvalid operator: $oid
class SimilarTargets
@queue = :similar_queue
def self.perform(target_id)
source_target = Target.find(target_id)
....
end
end
The worker is failing on Target.find(target_id), even when a straight string is passed in via the rails console.
Target.find(id) works fine in the console and elsewhere in the code and I can't figure out why this has failing even though the worker class has never changed in the last week.
Did you upgrade Mongoid recently? The error makes it sound like the .find() method is receiving something like {"$oid": "[STRING]"}
, which is the strict json representation of an Object ID for Mongo.
You can get around it with something like this, assuming you just want a quick fix:
target_id = target_id["$oid"] unless target_id.is_a?(String)
Another option is to ensure that when you enqueue a Moped::BSON::ObjectId you explicitly pass in a string representation. E.g.,
Resque.enqueue(MyJob, @mongoid_instance.class.to_s, @mongoid_instance.id.to_s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With