Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq: pass an object as parameter

I have a sidekiq worker that connects to a remote odbc database, fetches the data and then update the local database. Now I'm splitting the worker into two workers. One will connect and fetch the data and another will update the records.

The connection returns an object #<OCI8::Cursor:0x00000007703f30> that I'm passing in parameters to the second worker.

SecondWorker.perform_async({:odbc => connection})

In the second worker I tried to use it:

def perform(options)
  order_odbc = options['odbc']
end

But it treats the object as string

"#<OCI8::Cursor:0x00000006bddf48>":String

Is there any other way to pass the objects in parameters?

like image 998
Arif Avatar asked Dec 06 '25 07:12

Arif


1 Answers

Sidekiq recommends that arguments to jobs be passed as simple data types (string, integer, etc.).

My question for you - and I recognize this might not be an option within your business rules and constraints - is "do you really need a second Worker"?

I might look at an option with a service or other class doing the work; rather than kicking off another worker.

# Inside First Worker 
SomeCoolClass.delay.method(params)

With delay, the method will process asynchronously and, in my experiences, I have not had an issue with complex objects in such scenarios (versus issues I have had when I passed complex objects/data to a worker).

As I mentioned, might not work for your application but wanted to offer the suggestion as it has worked for me in my use-cases.

like image 70
craig.kaminsky Avatar answered Dec 08 '25 22:12

craig.kaminsky