How to reproduce/sanitize messy POST params to avoid YAML serialization issues with delayed_job?

后端 未结 2 2026
挽巷
挽巷 2021-01-22 08:34

Today, every time I was starting delayed_job workers, the process would die immediately and silently.

After some investigation (and finding out about the fo

2条回答
  •  野性不改
    2021-01-22 09:16

    A detailed explanation of what @house9 is suggesting:

    Do NOT do the following (even though the delayed_job's git repo suggests is as example)

    Notifier.delay.signup(@user)
    
    class NotifierMailer < ActionMailer::Base
      def signup(user)
      end
    end
    

    as this will attempt to yaml encode @user (which can cause issues)

    But rather, any time you have an object (especially an AR object) that has an id, you should pass the id when calling the delayed job and retrieve it later:

    Notifier.delay.signup(@user.id)
    
    class NotifierMailer < ActionMailer::Base
      def signup(id)
         @user = User.find_by_id(id)
      end
    end
    

提交回复
热议问题