Class: Solidstats::DataCollectorService

Inherits:
Object
  • Object
show all
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

AuditService, TodoService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_file, cache_duration = 12.hours) ⇒ DataCollectorService

Initialize the data collector with cache configuration

Parameters:

  • Path to the cache file

  • (defaults to: 12.hours)

    Duration to keep the cache valid



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_durationObject (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_fileObject (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

Parameters:

  • (defaults to: false)

    Whether to force a refresh regardless of cache state

Returns:

  • The collected 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

#summaryHash

Get a summary of the data for dashboard display

Returns:

  • Summary information

Raises:



33
34
35
# File 'app/services/solidstats/data_collector_service.rb', line 33

def summary
  raise NotImplementedError, "Subclasses must implement summary"
end