我正在开发一个 Rails 应用程序,目前我们正在迁移到 jruby。我们目前在我们的一个模型上有超过 10 个后回调,这会长时间阻止响应。
after_update :sync
after_update :send
after_create :add
after_create :add
after_create :send
after_update :track!
after_create :track!
after_create :send_welcome_email
after_create :track
after_update :send
after_update :set_is_active!
after_update :set_
after_create :apply
after_update :apply
after_update :clear
after_create :mark
我需要包装/覆盖activerecord的后回调(after_save,after_update)以使用concurrent-ruby异步运行它们而不阻塞响应,但我不知道如何以正确的方式做到这一点。
我想做的是这样的
require 'concurrent'
class ApplicationRecord < ActiveRecord::Base
def after_update
Concurrent::Promise.new { super }.exec
end
end
我只需要知道正确的语法以及这是否是此类事情的正确方法。将不胜感激任何建议。