Search code examples
rubyconcurrencysidekiq

How to manage connections with Sidekiq?


Each worker should have it's own resource connection. I read the docs, but it wasn't clear if each thread runs a separate instance of the worker.

If so, does this create a connection that is unique to each worker?

class HardWorker
  include Sidekiq::Worker

  def perform 
    connection.send 'message'
  end

  def connection
    @connection ||= Connection.new
  end
end

Solution

  • Sidekiq basically does this when executing each job: HardWorker.new.perform. So, yes.