B Seven
B Seven

Reputation: 45941

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

Upvotes: 0

Views: 38

Answers (1)

Mike Perham
Mike Perham

Reputation: 22238

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

Upvotes: 1

Related Questions