Class: SolidObserver::StorageInfo

Inherits:
BaseEvent
  • Object
show all
Defined in:
app/models/solid_observer/storage_info.rb

Constant Summary collapse

MB_TO_BYTES =
1_048_576
GB_TO_BYTES =
1_073_741_824
COMPONENTS =
%w[queue_observer cache_observer solid_cache].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.record_snapshot(db_size:, event_count:, component: "queue_observer") ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/solid_observer/storage_info.rb', line 19

def self.record_snapshot(db_size:, event_count:, component: "queue_observer")
  create!(
    component: component,
    db_size_bytes: db_size || 0,
    event_count: event_count,
    recorded_at: Time.current
  )
rescue ActiveRecord::RecordInvalid => e
  Rails.logger.error "[SolidObserver] Failed to record storage snapshot: #{e.message}"
  raise
end

Instance Method Details

#db_size_gbObject



35
36
37
# File 'app/models/solid_observer/storage_info.rb', line 35

def db_size_gb
  (db_size_bytes / GB_TO_BYTES.to_f).round(2)
end

#db_size_mbObject



31
32
33
# File 'app/models/solid_observer/storage_info.rb', line 31

def db_size_mb
  (db_size_bytes / MB_TO_BYTES.to_f).round(2)
end