英文:
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 < ClassLoader
def initialize classes, symbols
@classes = classes + Psych::ClassLoader::ALLOWED_PSYCH_CLASSES.map(&:to_s)
@symbols = symbols
super()
end
end
end
end
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论