Class: PartitionGardener::RunMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/partition_gardener/run_metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ RunMetrics

Returns a new instance of RunMetrics.



6
7
8
9
10
11
12
13
14
# File 'lib/partition_gardener/run_metrics.rb', line 6

def initialize(table_name)
  @table_name = table_name
  @started_at = monotonic_clock
  @plan_signature = nil
  @rows_moved = 0
  @finished_at = nil
  @skipped = false
  @skip_reason = nil
end

Instance Attribute Details

#finished_atObject (readonly)

Returns the value of attribute finished_at.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def finished_at
  @finished_at
end

#plan_signatureObject

Returns the value of attribute plan_signature.



4
5
6
# File 'lib/partition_gardener/run_metrics.rb', line 4

def plan_signature
  @plan_signature
end

#rows_movedObject (readonly)

Returns the value of attribute rows_moved.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def rows_moved
  @rows_moved
end

#skip_reasonObject (readonly)

Returns the value of attribute skip_reason.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def skip_reason
  @skip_reason
end

#skippedObject (readonly)

Returns the value of attribute skipped.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def skipped
  @skipped
end

#started_atObject (readonly)

Returns the value of attribute started_at.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def started_at
  @started_at
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/partition_gardener/run_metrics.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#add_rows(count) ⇒ Object



16
17
18
# File 'lib/partition_gardener/run_metrics.rb', line 16

def add_rows(count)
  @rows_moved += count.to_i
end

#duration_msObject



30
31
32
33
34
# File 'lib/partition_gardener/run_metrics.rb', line 30

def duration_ms
  return nil unless @finished_at

  ((@finished_at - @started_at) * 1000).round
end

#finish!Object



26
27
28
# File 'lib/partition_gardener/run_metrics.rb', line 26

def finish!
  @finished_at = monotonic_clock
end

#mark_skipped!(reason) ⇒ Object



20
21
22
23
24
# File 'lib/partition_gardener/run_metrics.rb', line 20

def mark_skipped!(reason)
  @skipped = true
  @skip_reason = reason
  finish!
end

#to_hObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/partition_gardener/run_metrics.rb', line 36

def to_h
  {
    table_name: table_name,
    duration_ms: duration_ms,
    plan_signature: plan_signature,
    rows_moved: rows_moved,
    skipped: skipped,
    skip_reason: skip_reason
  }
end