Class: Solidstats::DataCollectorService
- Inherits:
-
Object
- Object
- Solidstats::DataCollectorService
- Defined in:
- app/services/solidstats/data_collector_service.rb
Overview
Base service class for all data collectors This class handles caching logic and provides a common interface for all data collection services in SolidStats
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cache_duration ⇒ Object
readonly
Returns the value of attribute cache_duration.
-
#cache_file ⇒ Object
readonly
Returns the value of attribute cache_file.
Instance Method Summary collapse
-
#fetch(force_refresh = false) ⇒ Hash
Fetch data with caching Returns cached data if available and not expired, otherwise collects fresh data.
-
#initialize(cache_file, cache_duration = 12.hours) ⇒ DataCollectorService
constructor
Initialize the data collector with cache configuration.
-
#summary ⇒ Hash
Get a summary of the data for dashboard display.
Constructor Details
#initialize(cache_file, cache_duration = 12.hours) ⇒ DataCollectorService
Initialize the data collector with cache configuration
13 14 15 16 |
# File 'app/services/solidstats/data_collector_service.rb', line 13 def initialize(cache_file, cache_duration = 12.hours) @cache_file = cache_file @cache_duration = cache_duration end |
Instance Attribute Details
#cache_duration ⇒ Object (readonly)
Returns the value of attribute cache_duration.
8 9 10 |
# File 'app/services/solidstats/data_collector_service.rb', line 8 def cache_duration @cache_duration end |
#cache_file ⇒ Object (readonly)
Returns the value of attribute cache_file.
8 9 10 |
# File 'app/services/solidstats/data_collector_service.rb', line 8 def cache_file @cache_file end |
Instance Method Details
#fetch(force_refresh = false) ⇒ Hash
Fetch data with caching Returns cached data if available and not expired, otherwise collects fresh data
23 24 25 26 27 28 29 |
# File 'app/services/solidstats/data_collector_service.rb', line 23 def fetch(force_refresh = false) return cached_data if fresh_cache? && !force_refresh data = collect_data save_to_cache(data) data end |
#summary ⇒ Hash
Get a summary of the data for dashboard display
33 34 35 |
# File 'app/services/solidstats/data_collector_service.rb', line 33 def summary raise NotImplementedError, "Subclasses must implement summary" end |