class Sidekiq::Slog::ServerMiddleware
Public Instance Methods
call(worker, msg, queue) { || ... }
click to toggle source
# File lib/sidekiq-slog/middleware.rb, line 54 def call(worker, msg, queue) Thread.current[:aj_job_id] = Sidekiq::Slog.job_id(msg) Thread.current[:aj_job_class] = Sidekiq::Slog.job_class(msg) context = { queue: queue } ts = Time.now.to_f # We are currently not logging start events. # This would most likely blow our SumoLogic limit. # start context, ts yield stop context, msg, ts rescue => ex error context, ex, ts raise ex ensure Thread.current[:aj_job_id] = nil Thread.current[:aj_job_class] = nil end
duration_ms(from, to = Time.now.to_f)
click to toggle source
# File lib/sidekiq-slog/middleware.rb, line 97 def duration_ms(from, to = Time.now.to_f) ((to - from) * 1000).round end
error(context, error, start)
click to toggle source
# File lib/sidekiq-slog/middleware.rb, line 78 def error(context, error, start) data = context.merge( at: :error, duration: duration_ms(start), error: error.class.name, message: error.message[/\A.+$/].inspect) SLog.log('job_error', data) end
start(context, _time)
click to toggle source
# File lib/sidekiq-slog/middleware.rb, line 74 def start(context, _time) SLog.log('job_start', context) end
stop(context, _msg, start)
click to toggle source
# File lib/sidekiq-slog/middleware.rb, line 87 def stop(context, _msg, start) data = context.merge( # It looks like this number is subject to clock drift. # TODO: Figure out a way to make this accurate. # queued_duration: duration_ms(msg['enqueued_at'], start), duration: duration_ms(start)) SLog.log('job_stop', data) end