Reputation: 1399
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?
Upvotes: 3
Views: 5880
Reputation: 137
You can transform your object in hash. This is not the best way, but it work.
More informations here to transform object into hash.
Upvotes: 0
Reputation: 5598
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.
Upvotes: 4