Class: Chronos::Integrations::Sidekiq::ServerMiddleware
- Inherits:
-
Object
- Object
- Chronos::Integrations::Sidekiq::ServerMiddleware
- Defined in:
- lib/chronos/integrations/sidekiq.rb
Overview
Captures Sidekiq execution timing and failures around the worker call.
Instance Method Summary collapse
- #call(worker, job, queue) ⇒ Object
-
#initialize(options = {}) ⇒ ServerMiddleware
constructor
A new instance of ServerMiddleware.
Constructor Details
#initialize(options = {}) ⇒ ServerMiddleware
Returns a new instance of ServerMiddleware.
133 134 135 136 137 138 |
# File 'lib/chronos/integrations/sidekiq.rb', line 133 def initialize( = {}) @notifier = [:notifier] || Chronos @clock = [:clock] || proc { monotonic_time } @wall_clock = [:wall_clock] || proc { Time.now.to_f } @limiter = [:limiter] || JobPayload.new end |
Instance Method Details
#call(worker, job, queue) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/chronos/integrations/sidekiq.rb', line 140 def call(worker, job, queue) started_at = @clock.call payload = base_payload(worker, job, queue) context = execution_context(job, payload) @notifier.with_context(context) do begin result = yield finish(payload, started_at, "completed") result rescue Exception => error # rubocop:disable Lint/RescueException finish(payload, started_at, "failed", error) notify_failure(error, payload) raise end end end |