Ruby on rails 延迟作业仅在heroku上失败
我有一个简单的作业,在本地运行(在开发、生产和登台中),但在heroku(生产和登台)上失败 命令是Ruby on rails 延迟作业仅在heroku上失败,ruby-on-rails,heroku,algolia,Ruby On Rails,Heroku,Algolia,我有一个简单的作业,在本地运行(在开发、生产和登台中),但在heroku(生产和登台)上失败 命令是DoctorLocation.reindex这是用于algolia的方法 引发的错误是NameError:uninitialized constant DoctorProfile::Recommension: app[worker.1]: [Worker(host:c304ffd7-6c21-4eeb-b423-d42fae5d2adb pid:4)] Job DoctorLocation.rei
DoctorLocation.reindex代码>这是用于algolia的方法
引发的错误是NameError:uninitialized constant DoctorProfile::Recommension
:
app[worker.1]: [Worker(host:c304ffd7-6c21-4eeb-b423-d42fae5d2adb pid:4)] Job DoctorLocation.reindex! (id=70) FAILED (3 prior attempts) with NameError: uninitialized constant DoctorProfile::Recommendation
奇怪的是,DoctorLocation.reindex
能够在控制台中成功运行,只有在使用延迟作业时才会失败
另外,请注意,DoctorProfile
和Recommendation
是两个独立的模型,这使得此错误更加令人困惑
更新:医生位置模型的代码:
class DoctorLocation < ApplicationRecord
include AlgoliaSearch
include AlgoliaDelayedJob
belongs_to :doctor_profile
belongs_to :location
delegate :first_name, :last_name, :name, :photo_url, :gender, :practice, to: :doctor_profile
unless Rails.env.test?
algoliasearch :per_environment => true, if: :approved?,
id: :uuid, enqueue: :trigger_delayed_job do
attribute :id, :uuid, :first_name, :last_name, :name, :photo_url, :gender,
:practice, :location
attribute :doctor_id do
doctor_profile.id
end
attribute :patients do
doctor_profile.patients.map{|x| {
uuid: x.uuid, photo_url: x.photo_url, first_name: x.first_name,
last_name: x.last_name, name: x.name, id: x.id
}}
end
attribute :reviews do
doctor_profile.reviews.map{|x| {
body: x.body,
patient_profile_photo_url: x.patient_profile.photo_url,
patient_profile_uuid: x.patient_profile.uuid,
patient_profile_id: x.patient_profile.id,
patient_profile_name: x.patient_profile.name
}}
end
attribute :patient_count do
doctor_profile.patients.length
end
attribute :patient_ids do
doctor_profile.patients.map(&:uuid)
end
attribute :insurances do
doctor_profile.insurance_providers.map{|x| "#{x.category}:#{x.name}"}
end
attribute :specialties do
doctor_profile.specialties.map(&:name)
end
geoloc :lat, :lon
tags do
doctor_profile.specialties.map(&:name)
end
attribute :group_ids do
doctor_profile.patients.map{|x| x.group_ids }.flatten.compact.uniq
end
attribute :liked_by_friends_of_user_id do
doctor_profile.patients.map{ |x|x.friend_ids }.flatten.compact.uniq
end
attributesToIndex ['first_name', 'last_name', 'name']
attributesForFaceting [
:insurances, :gender, :patient_ids, :liked_by_friends_of_user_id,
:group_ids
]
customRanking ['desc(patient_count)']
end
end
private
def approved?
doctor_profile.approved
end
def lat
location.latitude
end
def lon
location.longitude
end
end
你能发布你的DoctorLocation
模型的代码吗?@DanielWestendorf添加了完整的模型…algolia的东西有点乱…有没有用于#reindex的代码!方法?或者这是algolia gem/模块的一部分?听起来这是一个名称空间问题-它显然是在DoctorProfile名称空间中查找推荐模型。@user2954587我想这与自动加载有关。问题是错误消息的信息量不大——不清楚哪个建议引用没有被正确查找(我在代码中没有看到)。您可以尝试查找这些引用,并明确告诉它使用::Recommension,然后看看这是否可以修复它。我还怀疑这与Heroku本身无关,而是文件加载的顺序。你真的不能在生产模式下本地复制吗?你能发布你的DoctorLocation
模型的代码吗?@DanielWestendorf添加了完整的模型…algolia的东西有点乱…有没有用于#reindex的代码!方法?或者这是algolia gem/模块的一部分?听起来这是一个名称空间问题-它显然是在DoctorProfile名称空间中查找推荐模型。@user2954587我想这与自动加载有关。问题是错误消息的信息量不大——不清楚哪个建议引用没有被正确查找(我在代码中没有看到)。您可以尝试查找这些引用,并明确告诉它使用::Recommension,然后看看这是否可以修复它。我还怀疑这与Heroku本身无关,而是文件加载的顺序。你真的不能在生产模式下本地复制吗?
module AlgoliaDelayedJob
extend ActiveSupport::Concern
module ClassMethods
def trigger_delayed_job(record, remove)
if remove
# record not saved, so delete from index by id
# (can't instantiate the model and call .delay.remove_from_index!)
index = Algolia::Index.new("#{self.name}_#{Rails.env}")
index.delete_object(record.uuid)
else
obj = self.find(record.id)
obj.index!
end
end
end
end