Sha256: 1a1e3b93d89caf7cc474fe33d24ae528b266fd005c541543a1e54cd4e5874e50

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

module RailsPerformance
  module Models
    class DelayedJobRecord < BaseRecord
      attr_accessor :jid, :duration, :datetime, :datetimei, :source_type, :class_name, :method_name, :status, :json

      # delayed_job
      # |jid|22
      # |datetime|20210415T0616
      # |datetimei|1618492591
      # |source_type|instance_method
      # |class_name|User
      # |method_name|say_hello_without_delay
      # |status|success|END|1.0.0
      def self.from_db(key, value)
        items = key.split("|")

        DelayedJobRecord.new(
          jid: items[2],
          datetime: items[4],
          datetimei: items[6],
          source_type: items[8],
          class_name: items[10],
          method_name: items[12],
          status: items[14],
          json: value
        )
      end

      def initialize(jid:, datetime:, datetimei:, source_type:, class_name:, method_name:, status:, duration: nil, json: "{}")
        @jid = jid
        @duration = duration
        @datetime = datetime
        @datetimei = datetimei.to_i
        @source_type = source_type
        @class_name = class_name
        @method_name = method_name
        @status = status
        @json = json
      end

      def record_hash
        {
          jid: jid,
          datetime: RailsPerformance::Utils.from_datetimei(datetimei),
          datetimei: datetimei,
          duration: value["duration"],
          status: status,
          source_type: source_type,
          class_name: class_name,
          method_name: method_name
        }
      end

      def save
        key = "delayed_job|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|source_type|#{source_type}|class_name|#{class_name}|method_name|#{method_name}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
        value = {duration: duration}
        Utils.save_to_redis(key, value)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_performance-1.4.1 lib/rails_performance/models/delayed_job_record.rb
rails_performance-1.4.1.alpha1 lib/rails_performance/models/delayed_job_record.rb
rails_performance-1.4.0 lib/rails_performance/models/delayed_job_record.rb
rails_performance-1.4.0.alpha5 lib/rails_performance/models/delayed_job_record.rb
rails_performance-1.4.0.alpha4 lib/rails_performance/models/delayed_job_record.rb