我在 Sidekiq 作業人員中有以下方法:
def self.schedule_edits(course:, editing_user:, enrollment_results:)
puts editing_user.id
perform_async(course.id, editing_user.id, enrollment_results)
end
我有一個控制器測驗,當它呼叫此代碼時會引發以下警告:
WARN: Job arguments to MassEnrollmentWorker do not serialize to JSON safely. This will raise an error...
我已經閱讀了這里的警告,我猜注冊結果是有問題的論點。但是,當我運行測驗并輸出enrollment_results 時,我看到的是:
{"FirstUser"=>{:success=>"User added to course."}, "SecondUser"=>{:success=>"User added to course."}, "NotARealUserOnWikipedia"=>{:failure=>"Not an existing user."}
這似乎是一個有效的哈希,那么問題是什么?
uj5u.com熱心網友回復:
注意關于符號的部分。
https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
傳遞給 perform_async 的引數必須由簡單的 JSON 資料型別組成:string、integer、float、boolean、null(nil)、array 和 hash。這意味著您不能使用 ruby?? 符號作為引數。
uj5u.com熱心網友回復:
為了后代;我通過改變哈希的構建方式來解決這個問題:
{"FirstUser"=>{:success=>"User added to course."}, "SecondUser"=>{:success=>"User added to course."}, "NotARealUserOnWikipedia"=>{:failure=>"Not an existing user."}
到...
{"FirstUser"=>{"success"=>"User added to course."}, "SecondUser"=>{"success"=>"User added to course."}, "NotARealUserOnWikipedia"=>{"failure"=>"Not an existing user."}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/437157.html
