Class: SolidObserver::Services::StorageInfoSnapshot::Component

Inherits:
Struct
  • Object
show all
Defined in:
lib/solid_observer/services/storage_info_snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled

Returns:

  • (Object)

    the current value of enabled



8
9
10
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 8

def enabled
  @enabled
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



8
9
10
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 8

def key
  @key
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



8
9
10
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 8

def label
  @label
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



8
9
10
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 8

def model
  @model
end

#record_labelObject

Returns the value of attribute record_label

Returns:

  • (Object)

    the current value of record_label



8
9
10
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 8

def record_label
  @record_label
end

Instance Method Details

#available_snapshot(db_size_bytes:, event_count:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 38

def available_snapshot(db_size_bytes:, event_count:)
  {
    component: key,
    label: label,
    available: true,
    db_size_bytes: db_size_bytes,
    event_count: event_count,
    record_label: record_label,
    recorded_at: Time.current,
    unavailable_reason: nil
  }
end

#data_source_exists?(connection, table_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 21

def data_source_exists?(connection, table_name)
  connection.data_source_exists?(table_name)
end

#database_size(connection, table_name) ⇒ Object



25
26
27
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 25

def database_size(connection, table_name)
  DatabaseSize.call(connection: connection, table_name: table_name)
end

#enabled?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 9

def enabled?
  enabled.call
end

#snapshotObject



29
30
31
32
33
34
35
36
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 29

def snapshot
  return unless enabled?
  return unavailable_snapshot(reason: "SolidCache is unavailable") if unavailable_solid_cache?

  existing_data_source_snapshot
rescue *StorageInfoSnapshot::CONNECTION_ERRORS, TypeError
  unavailable_snapshot(reason: "Storage unavailable")
end

#solid_cache?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 13

def solid_cache?
  key == "solid_cache"
end

#storage_modelObject



17
18
19
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 17

def storage_model
  model.call
end

#unavailable_snapshot(reason:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 51

def unavailable_snapshot(reason:)
  {
    component: key,
    label: label,
    available: false,
    db_size_bytes: nil,
    event_count: nil,
    record_label: record_label,
    recorded_at: nil,
    unavailable_reason: reason
  }
end