divergent
divergent

Reputation: 291

Sidekiq throws 'Active Record Unknown Primary Key Error' on Active Type object

I am using the Sidekiq gem in my Rails app to handle some long-running processes asynchronously. As illustrated in this Railscast, a reference to the model to be processed is passed as an argument to the perform_async method of the worker class doing the background processing.

This would not be a problem if the model in question was an Active Record object. However it is an Active Type object designed to "quack like ActiveRecord" and unfortunately it does not quack as loudly so I get an ActiveRecord::UnknownPrimaryKeyError.

How do I set a primary key for a Ruby object that really is not a db object and convince Sidekiq to treat it as such? Unable to glean information on how to do this from the Active Type Github page.

Any help will be greatly appreciated!

Upvotes: 1

Views: 381

Answers (1)

user3790827
user3790827

Reputation: 815

It depends on what do you want to do with your Active Type Object. As the Documentation states

The arguments you pass to perform_async must be composed of simple JSON datatypes: string, integer, float, boolean, null, array and hash.

If you don't have an id to identify the Object( from your post I understand that you don't), then the best solution would be to convert the Object to a Hash and then pass it to perform_async . But as I said, it depends on what you data you need from your Object. In some cases you might not need to use a hash and a simpler data type will suffice.

Upvotes: 0

Related Questions