Class: Loggery::Metadata::Middleware::Sidekiq

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/loggery/metadata/middleware/sidekiq.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#log_job_runtime

Class Attribute Details

.error_handlerObject

Returns the value of attribute error_handler.



13
14
15
# File 'lib/loggery/metadata/middleware/sidekiq.rb', line 13

def error_handler
  @error_handler
end

Instance Method Details

#call(_worker, message, queue) ⇒ Object



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

def call(_worker, message, queue)
  Loggery::Metadata::Store.((message, queue)) do
    job_instance_name = "#{message['class']} (#{message['args']})"
    log_job_start(message, job_instance_name)

    log_job_runtime(:sidekiq_job, job_instance_name) do
      yield
    rescue StandardError => e
      # Log exceptions here, otherwise they won't have the metadata available anymore by
      # the time they reach the Sidekiq default error handler.
      self.class.error_handler&.call(e)
      raise e
    end
  end
end