Sha256: b4ca5df1e11b2adfd0db89b025b48a8ebe5b934db2873525f0cafb6a8e592886
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
module JuanPelota module Middlewares class Logging # rubocop:disable Lint/RescueException, Metrics/AbcSize, Metrics/MethodLength def call(worker, job, _queue) start = Time.now unless config.filtered_workers.include? worker.class.name logger.info( 'status' => 'start', 'jid' => job['jid'], 'bid' => job['bid'], 'run_time' => nil, 'class' => worker.class.to_s, 'args' => filtered_arguments(job['args']), ) end yield unless config.filtered_workers.include? worker.class.name logger.info( 'status' => 'done', 'jid' => job['jid'], 'bid' => job['bid'], 'run_time' => elapsed(start), 'class' => worker.class.to_s, 'args' => filtered_arguments(job['args']), ) end rescue Exception logger.info( 'status' => 'fail', 'jid' => job['jid'], 'bid' => job['bid'], 'run_time' => elapsed(start), 'class' => worker.class.to_s, 'args' => filtered_arguments(job['args']), ) raise end # rubocop:enable Lint/RescueException, Metrics/AbcSize, Metrics/MethodLength def elapsed(start) (Time.now - start).to_f.round(3) end def logger Sidekiq.logger end def filtered_arguments(args) return unless args @filtered_arguments ||= args.each_with_object({}) do |(key, value), filtered_hash| filtered_hash[key] = value unless config.filtered_arguments.include? key end end private def config Configuration.instance end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
juan_pelota-0.0.4 | lib/juan_pelota/middlewares/logging.rb |