Sha256: 176f8acdbdf41997204144917be9b05b08ce12f987cb230ceb56db9d1bd56148

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

module RailsPerformance
  module Models
    class SidekiqRecord < BaseRecord
      attr_accessor :queue, :worker, :jid, :datetimei, :enqueued_ati, :datetime, :start_timei, :status, :duration, :message

      # key = job-performance
      # |queue|default
      # |worker|SimpleWorker
      # |jid|7d48fbf20976c224510dbc60
      # |datetime|20200124T0523
      # |datetimei|1583146613
      # |enqueued_ati|1583146613
      # |start_timei|1583146614
      # |status|success|END|1.0.0
      # value = JSON
      def self.from_db(key, value)
        items = key.split("|")

        SidekiqRecord.new(
          queue: items[2],
          worker: items[4],
          jid: items[6],
          datetime: items[8],
          datetimei: items[10],
          enqueued_ati: items[12],
          start_timei: items[14],
          status: items[16],
          json: value
        )
      end

      def initialize(queue:, worker:, jid:, datetime:, datetimei:, enqueued_ati:, start_timei:, status: nil, duration: nil, json: "{}")
        @queue = queue
        @worker = worker
        @jid = jid
        @datetime = datetime
        @datetimei = datetimei.to_i
        @enqueued_ati = enqueued_ati
        @start_timei = start_timei
        @status = status
        @duration = duration
        @json = json
      end

      def record_hash
        {
          worker: worker,
          queue: queue,
          jid: jid,
          status: status,
          datetimei: datetimei,
          datetime: Time.at(start_timei.to_i),
          duration: value["duration"],
          message: value["message"]
        }
      end

      def save
        key = "sidekiq|queue|#{queue}|worker|#{worker}|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|enqueued_ati|#{enqueued_ati}|start_timei|#{start_timei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
        value = {message: message, duration: duration}
        Utils.save_to_redis(key, value)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_performance-1.4.0.alpha3 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.4.0.alpha2 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.4.0.alpha1 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.3.3 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.3.2 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.3.1 lib/rails_performance/models/sidekiq_record.rb
rails_performance-1.3.0 lib/rails_performance/models/sidekiq_record.rb