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



59
60
61
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 59

def enabled
  @enabled
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



59
60
61
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 59

def key
  @key
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



59
60
61
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 59

def label
  @label
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



59
60
61
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 59

def model
  @model
end

#record_labelObject

Returns the value of attribute record_label

Returns:

  • (Object)

    the current value of record_label



59
60
61
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 59

def record_label
  @record_label
end

Instance Method Details

#available_snapshot(db_size_bytes:, event_count:, **extras) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 86

def available_snapshot(db_size_bytes:, event_count:, **extras)
  {
    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
  }.merge(extras)
end

#enabled?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 60

def enabled?
  enabled.call
end

#snapshotObject



76
77
78
79
80
81
82
83
84
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 76

def snapshot
  return unless enabled?
  return unavailable_snapshot(reason: "SolidCache is unavailable") if unavailable_solid_cache?
  return unavailable_snapshot(reason: "SolidCable is unavailable") if solid_cable? && !defined?(::SolidCable::Message)

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

#solid_cable?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 68

def solid_cable?
  key == "solid_cable"
end

#solid_cache?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 64

def solid_cache?
  key == "solid_cache"
end

#storage_modelObject



72
73
74
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 72

def storage_model
  model.call
end

#unavailable_snapshot(reason:) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/solid_observer/services/storage_info_snapshot.rb', line 99

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