Sha256: c5c255d14117773605fc399f2958cb24d981a7853ebbd593054aba9d9142184d

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module LiveQA
  module Plugins
    module Sidekiq
      ##
      # LiveQA \Plugins \Sidekiq \Server \Middleware
      #
      # Server middleware for sidekiq
      #
      class ServerMiddleware

        def call(_worker, job, _queue)
          LiveQA::Store.set(:session_tracker_id, job['liveqa_session_tracker_id'] || SecureRandom.uuid)
          store_worker_data(job)
          yield
        ensure
          LiveQA::Store.clear!
        end

        private

        def store_worker_data(job)
          LiveQA::Store.set(
            :worker,
            name: 'sidekiq',
            version: ::Sidekiq::VERSION,
            queue: job['queue'],
            class: job['class'],
            id: job['jid'],
            created_at: convert_to_iso8601(job['created_at']),
            process_at: convert_to_iso8601(job['enqueued_at']),
            args: job['args'],
            retried: job['retry_count'].is_a?(Integer),
            retry_number: job['retry_count'],
            failed_at: convert_to_iso8601(job['failed_at'])
          )
        end

        def convert_to_iso8601(int_time)
          Time.at(int_time).utc.iso8601(3)
        rescue StandardError => _e
          nil
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
liveqa-1.9.5 lib/liveqa/plugins/sidekiq/server_middleware.rb
liveqa-1.9.4 lib/liveqa/plugins/sidekiq/server_middleware.rb
liveqa-1.9.3 lib/liveqa/plugins/sidekiq/server_middleware.rb
liveqa-1.9.2 lib/liveqa/plugins/sidekiq/server_middleware.rb
liveqa-1.9.1 lib/liveqa/plugins/sidekiq/server_middleware.rb
liveqa-1.9.0 lib/liveqa/plugins/sidekiq/server_middleware.rb