Sha256: a2ee77dc1fed0378379003e0b20a322126c7d52f375207e24a8de7020e4602cf

Contents?: true

Size: 817 Bytes

Versions: 1

Compression:

Stored size: 817 Bytes

Contents

module Pliny::Sidekiq
  class JobLogger
    def call(job, queue)
      context = {
        sidekiq: true,
        job:     job['class'],
        job_jid:  job['jid'],
        job_retry: job['retry'],
      }

      begin
        start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
        log(context, job_logger: true, at: :start)
        yield
        log(context, job_logger: true, at: :finish, status: :done, duration: elapsed(start))
      rescue Exception
        log(context, job_logger: true, at: :finish, status: :fail, duration: elapsed(start))
        raise
      end
    end

    private

    def log(context, data = {}, &blk)
      Pliny.log(context.merge(data), &blk)
    end

    def elapsed(start)
      (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pliny-sidekiq-0.3.0 lib/pliny/sidekiq/job_logger.rb