Rails 测试触发 Sidekiq 警告

Rails test triggers Sidekiq warning

我在 Sidekiq worker 中有以下方法:

  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...

我已经阅读了警告 HERE,我猜 enrollment_results 是令人反感的论点。但是,当我 运行 测试并输出 enrollment_results 时,这是我看到的:

{"FirstUser"=>{:success=>"User added to course."}, "SecondUser"=>{:success=>"User added to course."}, "NotARealUserOnWikipedia"=>{:failure=>"Not an existing user."}

这似乎是一个有效的散列,那么问题是什么?

注意有关符号的部分。

https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple

The arguments you pass to perform_async must be composed of simple JSON datatypes: string, integer, float, boolean, null(nil), array and hash. This means you must not use ruby symbols as arguments.

为子孙后代;我通过更改哈希的构建方式来解决此问题:

{"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."}