Ruby on rails 如何在提交(sunspot注入)后异步调用
我用的是带轨道的太阳黑子。 我知道太阳黑子会在提交后使用Ruby on rails 如何在提交(sunspot注入)后异步调用,ruby-on-rails,sunspot,Ruby On Rails,Sunspot,我用的是带轨道的太阳黑子。 我知道太阳黑子会在提交后使用钩子重新索引。。。 但是,如果在提交失败后,事务将回滚,并且要保存的帐户(ActiveRecord::Base)将被删除 我想使用sidekiq,perform\u async在提交后调用,但不知道如何实现 有什么建议吗?模块重新索引 module Reindex extend ActiveSupport::Concern def async_reindex AsyncIndexJob.pe
钩子重新索引。。。
但是,如果在提交失败后,事务将回滚,并且要保存的帐户(ActiveRecord::Base)
将被删除
我想使用sidekiq,perform\u async
在提交后调用,但不知道如何实现
有什么建议吗?模块重新索引
module Reindex
extend ActiveSupport::Concern
def async_reindex
AsyncIndexJob.perform_later(self.class.to_s, self.reload.id)
end
included do
after_save :async_reindex
end
end
class AsyncIndexJob < ActiveJob::Base
queue_as :index
def perform(*args)
obj = args[0].constantize.find_by_id(args[1])
if obj
Sunspot.index obj
Sunspot.commit
end
end
end
扩展ActiveSupport::关注点
def异步_重新索引
AsyncIndexJob.perform_later(self.class.to_s,self.reload.id)
结束
包括做
保存后:异步重新索引
结束
结束
类AsyncIndexJob
1.在ActiveRecord::Base中包含Reindex模块
2.set:auto_index=>false
全部完成
模块重新索引
扩展ActiveSupport::关注点
def异步_重新索引
AsyncIndexJob.perform_later(self.class.to_s,self.reload.id)
结束
包括做
保存后:异步重新索引
结束
结束
类AsyncIndexJob
1.在ActiveRecord::Base中包含Reindex模块
2.set:auto_index=>false
全部完成