ruby-on-railssidekiqwisper

Rails wisper-sidekiq is not working for asynchronous jobs


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


Solution

  • 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