Sha256: c26bb957deee3f401ec5d14910746ffa526d02df4ecca5bc34b494b6fda1c5f9

Contents?: true

Size: 1.36 KB

Versions: 23

Compression:

Stored size: 1.36 KB

Contents

module RailsPerformance
  module Models
    class RakeRecord < BaseRecord
      attr_accessor :task, :duration, :datetime, :datetimei, :status

      # rake|task|["task3"]|datetime|20210416T1254|datetimei|1618602843|status|error|END|1.0.0
      # {"duration":0.00012442}
      def RakeRecord.from_db(key, value)
        items = key.split("|")

        RakeRecord.new(
          task: JSON.parse(items[2]),
          datetime: items[4],
          datetimei: items[6],
          status: items[8],
          json: value
        )
      end

      def initialize(task:, duration: nil, datetime:, datetimei:, status:, json: '{}')
        @task         = Array.wrap(task)
        @datetime     = datetime
        @datetimei    = datetimei.to_i
        @status       = status
        @duration     = duration
        @json         = json

        @duration ||= value['duration']
      end

      def record_hash
        {
          task: task,
          datetime: Time.at(datetimei),
          datetimei: datetimei,
          duration: duration,
          status: status,
        }
      end

      def save
        key   = "rake|task|#{task.to_json}|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/rake_record.rb
rails_performance-1.2.2 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.1 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0.alpha5 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0.alpha4 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0.alpha3 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0.alpha2 lib/rails_performance/models/rake_record.rb
rails_performance-1.2.0.alpha1 lib/rails_performance/models/rake_record.rb
rails_performance-1.1.0 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.5.3 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.5.2 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.5.1 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.5 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.4 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.3 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.2 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.1 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.0 lib/rails_performance/models/rake_record.rb
rails_performance-1.0.0.beta5 lib/rails_performance/models/rake_record.rb