Deserialization error while processing job rails

716 Views Asked by At

I am trying to create background jobs for mailer using AWS worker, By overriding devise method

def send_devise_notification(notification, *args)
    devise_mailer.send(notification, id, *args).deliver_later
  end

I am pushing the mailer to the SQS queue, While the worker processes the job(ActiveJob::Base.execute(params) I am getting the following error

{"job_class"=>"ActionMailer::DeliveryJob", "job_id"=>"4153057f-3811-4f41-9e90-b37187c91a91", "provider_job_id"=>nil, "queue_name"=>"DevelopmentJobs", "priority"=>nil, "arguments"=>["DeviseMailer", "reset_password_instructions", "deliver_now", 54, "3LsoHzn6F_ySZpkjefw4", {"_aj_symbol_keys"=>[]}], "executions"=>0, "locale"=>"en", "process_sqs_job"=>{"job_class"=>"ActionMailer::DeliveryJob", "job_id"=>"4153057f-3811-4f41-9e90-b37187c91a91", "provider_job_id"=>nil, "queue_name"=>"DevelopmentJobs", "priority"=>nil, "arguments"=>["DeviseMailer", "reset_password_instructions", "deliver_now", 54, "3LsoHzn6F_ySZpkjefw4", {"_aj_symbol_keys"=>[]}], "executions"=>0, "locale"=>"en"}}
    I, [2018-06-05T15:03:30.055439 #23265]  INFO -- : [87592310-03d0-4223-af65-292798b3da88] Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
    F, [2018-06-05T15:03:30.056349 #23265] FATAL -- : [87592310-03d0-4223-af65-292798b3da88]   
    F, [2018-06-05T15:03:30.056453 #23265] FATAL -- : [87592310-03d0-4223-af65-292798b3da88] ActiveJob::DeserializationError (Error while trying to deserialize arguments: Can only deserialize primitive arguments: <ActionController::Parameters {"_aj_symbol_keys"=>[]} permitted: false>):
1

There are 1 best solutions below

0
Aarthi On BEST ANSWER

Active job deserializes the primitive arguments and it throws exception for action controller parameter, after changing the parameters into hash before passing the job to execute method, It processes the job

 def deserialize_argument(argument)
        case argument
        when String
          GlobalID::Locator.locate(argument) || argument
        when *TYPE_WHITELIST
          argument
        when Array
          argument.map { |arg| deserialize_argument(arg) }
        when Hash
          if serialized_global_id?(argument)
            deserialize_global_id argument
          elsif custom_serialized?(argument)
            Serializers.deserialize(argument)
          else
            deserialize_hash(argument)
          end
        else
          raise ArgumentError, "Can only deserialize primitive arguments: #{argument.inspect}"
        end
      end