Reputation: 95
I have a rails application which caches data from external service and also converts it to json. External service uses it's own protocol based on RPC convention.
Basically i need a background worker which keeps a connection alive by pinging back and forth using that protocol. When the rails app sends jobs to it, the worker translates it to queries for an external service and transmits converted json data back to application. Application then caches it and transmits it back to user.
The different approach is to use sidekiq and connect/disconnect on each job. This is inefficient.
I need some advice on this topic. Maybe even a different approach. Thanks in advance!
Upvotes: 1
Views: 376
Reputation: 22228
Set up a pool of connections to be used by the jobs running within Sidekiq.
Upvotes: 1
Reputation: 1352
You could create a global instance of the connection client, either when the sidekiq process starts or on the first request. I would assume that the client is single threaded which you could deal with by setting the concurrency
level of Sidekiq to 1. If that is an issue then you will need to do something more complex like creating a pool of connections.
Upvotes: 1