2

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?

Arif
  • 1,369
  • 14
  • 39

2 Answers2

3

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.

craig.kaminsky
  • 5,588
  • 28
  • 31
  • Thanks. The goal is to minimize the work load of the first worker as it first connects to the server, fetches the data and then updates the records. So, I thought to start a new worker. – Arif May 04 '16 at 08:06
  • Since you'd be kicking off the other method (i.e., the code that would represent the "second worker") as an async method, it does free up the Worker itself. I am not sure - but may be wrong - that you would get any "gains" from moving that code into a second worker. By using the async `delay` call, the worker moves on, etc. – craig.kaminsky May 04 '16 at 14:51
0

You can transform your object in hash. This is not the best way, but it work.

More informations here to transform object into hash.

Community
  • 1
  • 1
Florian B
  • 131
  • 1
  • 2
  • 14