Rails wisper-sidekiq在异步作业中不起作用

huangapple go评论47阅读模式
英文:

Rails wisper-sidekiq is not working for asynchronous jobs

问题

我在我的gemfile中添加了wisper-sidekiq,当我尝试使用async: true广播事件时,它失败并显示错误信息:

Psych::DisallowedClass:
尝试加载未指定的类:Listener::Studentlistener

然而,如果我将async: false,它可以正常工作。

wisper-sidekiq版本:1.0
sidekiq版本:6.5
rails版本:6.1

当我将async: false时,它可以正常工作,但是当我将async: true时,它不起作用。

英文:

can someone help me with this,
I added wisper-sidekiq in my gemfile, and when I tried to broadcast event with async: true it is failing with error
Psych::DisallowedClass:
Tried to load unspecified class: Listener::Studentlistener
whereas if I set the async: false it is working fine

wisper-sidekiq version: 1.0
sidekiq-version: 6.5
rails version: 6.1

I tried setting async: false it is working fine, but when I set async: true it's not working

答案1

得分: 0

Ruby在内部使用psych gem来处理yaml。在较新的Rails版本中,默认情况下不会加载未经您批准的任意yaml。

需要添加一个初始化器来告诉psych yaml加载程序允许什么...

Psych::ClassLoader::ALLOWED_PSYCH_CLASSES = [
  Listener::Studentlistener
]

module Psych
  class ClassLoader
    ALLOWED_PSYCH_CLASSES = [] unless defined? ALLOWED_PSYCH_CLASSES
    class Restricted < ClassLoader
      def initialize(classes, symbols)
        @classes = classes + Psych::ClassLoader::ALLOWED_PSYCH_CLASSES.map(&:to_s)
        @symbols = symbols
        super()
      end
    end
  end
end
英文:

Ruby uses the psych gem under the covers to deal with yaml. In later rails versions, the default is to NOT load arbitrary yaml without your approval.

Need to add an initializer to tell the psych yaml loader what is allowed...

Psych::ClassLoader::ALLOWED_PSYCH_CLASSES = [
                                              Listener::Studentlistener
                                            ]

module Psych
  class ClassLoader
    ALLOWED_PSYCH_CLASSES = [] unless defined? ALLOWED_PSYCH_CLASSES
    class Restricted &lt; ClassLoader
      def initialize classes, symbols
        @classes = classes + Psych::ClassLoader::ALLOWED_PSYCH_CLASSES.map(&amp;:to_s)
        @symbols = symbols
        super()
      end
    end
  end
end

huangapple
  • 本文由 发表于 2023年6月22日 16:24:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定