Class: Sidekiq::Instrumental::Middleware::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/instrumental/middleware/base.rb

Overview

Shared base code for measuring stats for server and client sidekiq

Direct Known Subclasses

Client, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



12
13
14
# File 'lib/sidekiq/instrumental/middleware/base.rb', line 12

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/sidekiq/instrumental/middleware/base.rb', line 10

def config
  @config
end

Instance Method Details

#call(worker_instance, msg, queue, _redis_pool = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sidekiq/instrumental/middleware/base.rb', line 16

def call(worker_instance, msg, queue, _redis_pool = nil)
  start_time = Time.now
  result = yield
  elapsed = (Time.now - start_time).to_f

  return result unless config.enabled?

  track(
    ::Sidekiq::Stats.new,
    worker_instance,
    ::Sidekiq::Job.new(msg),
    queue, elapsed
  )

  result
end