Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails test triggers Sidekiq warning

I have the following method in a 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

I have a controller test that, when it calls this code throws the following warning:

WARN: Job arguments to MassEnrollmentWorker do not serialize to JSON safely. This will raise an error...

I have read up on the warning HERE and I'm guessing that enrollment_results is the offending argument. However, when I run the test and output enrollment_results, here is what I see:

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

This appears to be a valid hash, so what is the issue?

like image 851
Mark Locklear Avatar asked Sep 08 '25 07:09

Mark Locklear


1 Answers

Note the part about Symbols.

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.

like image 68
Mike Perham Avatar answered Sep 09 '25 22:09

Mike Perham