Sha256: e35689ce1a5dccdfd2be1e76b26d86eb3fe07b04481629a8d571715c3e60ac5d

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

module RailsPerformance
  module Models
    class CustomRecord < BaseRecord
      attr_accessor :tag_name, :namespace_name, :duration, :datetime, :datetimei, :status, :json

      def CustomRecord.from_db(key, value)
        items = key.split("|")

        CustomRecord.new(
          tag_name: items[2],
          namespace_name: items[4],
          datetime: items[6],
          datetimei: items[8],
          status: items[10],
          json: value
        )
      end

      def initialize(tag_name:, namespace_name: nil, duration: nil, datetime:, datetimei:, status:, json: '{}')
        @tag_name       = tag_name
        @namespace_name = namespace_name
        @duration       = duration
        @datetime       = datetime
        @datetimei      = datetimei.to_i
        @status         = status
        @json           = json
      end

      def record_hash
        {
          tag_name: self.tag_name,
          namespace_name: self.namespace_name,
          status: self.status,
          datetimei: datetimei,
          datetime: Time.at(self.datetimei.to_i),
          duration: self.value['duration'],
        }
      end

      def save
        key   = "custom|tag_name|#{tag_name}|namespace_name|#{namespace_name}|datetime|#{datetime}|datetimei|#{datetimei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
        value = { duration: duration }
        Utils.save_to_redis(key, value)
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rails_performance-1.2.3 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.2 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.1 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0.alpha5 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0.alpha4 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0.alpha3 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0.alpha2 lib/rails_performance/models/custom_record.rb
rails_performance-1.2.0.alpha1 lib/rails_performance/models/custom_record.rb
rails_performance-1.1.0 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.5.3 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.5.2 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.5.1 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.5 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.4 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.3 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.2 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.1 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.0 lib/rails_performance/models/custom_record.rb
rails_performance-1.0.0.beta5 lib/rails_performance/models/custom_record.rb