Rails : Sidekiq 4.0 : no :symbol keys supported when hash is passed as argument

 

NotificationAsync.perform_later({data:{pact_id: 1}, context: OrdersSignup::Notification::WelcomeChild.to_s})

I was sending Hash as a parameter/argument to my worker but it was now able to access the keys/values using :symbol as a key name

So Explicitly use ActiveSupport’s `.with_indifferent_access`

def perform(params)
  params = params.with_indifferent_access
  binding.pry
  if params[:data][:pact_id]
    params[:data][:pact] = Pact.find(params[:data][:pact_id])
  elsif params[:data][:user_id]
    params[:data][:user] = User.find(params[:data][:user_id])
  end

  NotificationHandler.new(params).send
end

 

# Class Name in 'Context' Need to constantize
# Reason: Sidekiq can handle Class as an argument
#   but ActiveJob cannot
params[:context] = params[:context].constantize

Source:

personal experience

https://rubygems.org/gems/sidekiq/versions/4.0.1

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s