Class: Txnap::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/txnap/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outcome:, transaction_duration:, database_time:, gaps:, sql_count:) ⇒ Report

Returns a new instance of Report.



35
36
37
38
39
40
41
42
43
# File 'lib/txnap/report.rb', line 35

def initialize(outcome:, transaction_duration:, database_time:, gaps:, sql_count:)
  @outcome = outcome
  @transaction_duration = transaction_duration
  @database_time = database_time
  @gaps = gaps.freeze
  @longest_gap = gaps.first
  @locks = (@longest_gap&.locks || []).freeze
  @sql_count = sql_count
end

Instance Attribute Details

#database_timeObject (readonly)

Returns the value of attribute database_time.



27
28
29
# File 'lib/txnap/report.rb', line 27

def database_time
  @database_time
end

#gapsObject (readonly)

Returns the value of attribute gaps.



27
28
29
# File 'lib/txnap/report.rb', line 27

def gaps
  @gaps
end

#locksObject (readonly)

Returns the value of attribute locks.



27
28
29
# File 'lib/txnap/report.rb', line 27

def locks
  @locks
end

#longest_gapObject (readonly)

Returns the value of attribute longest_gap.



27
28
29
# File 'lib/txnap/report.rb', line 27

def longest_gap
  @longest_gap
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



27
28
29
# File 'lib/txnap/report.rb', line 27

def outcome
  @outcome
end

#sql_countObject (readonly)

Returns the value of attribute sql_count.



27
28
29
# File 'lib/txnap/report.rb', line 27

def sql_count
  @sql_count
end

#transaction_durationObject (readonly)

Returns the value of attribute transaction_duration.



27
28
29
# File 'lib/txnap/report.rb', line 27

def transaction_duration
  @transaction_duration
end

Instance Method Details

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/txnap/report.rb', line 45

def to_h
  {
    outcome: outcome,
    transaction_duration_ms: transaction_duration * 1000.0,
    database_time_ms: database_time * 1000.0,
    longest_gap_ms: longest_gap.duration * 1000.0,
    sql_count: sql_count,
    gap: longest_gap.to_h,
    gaps: gaps.map(&:to_h),
    locks: locks.map(&:to_h)
  }
end