Class: MultipleMan::SidekiqMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/multiple_man_sidekiq/middleware/sidekiq_middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(worker, job, queue) ⇒ Object


3
4
5
6
7
8
# File 'lib/multiple_man_sidekiq/middleware/sidekiq_middleware.rb', line 3

def call(worker, job, queue)
  establish_channel if is_middleman_job?
  yield
ensure
  close_channel if is_middleman_job?
end

#close_channelObject


14
15
16
17
# File 'lib/multiple_man_sidekiq/middleware/sidekiq_middleware.rb', line 14

def close_channel
  connection = Thread.local[:multiple_man_connection]
  connection.close_channel if connection && connection.open_channel?
end

#establish_channelObject


10
11
12
# File 'lib/multiple_man_sidekiq/middleware/sidekiq_middleware.rb', line 10

def establish_channel
  Thread.local[:multiple_man_connection] = MultipleMan::Connection.new
end

#is_middleman_job?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/multiple_man_sidekiq/middleware/sidekiq_middleware.rb', line 19

def is_middleman_job?
  worker.kind_of? MultipleMan::ModelPublisherJob
end