Class: Tasker::Health::StatusChecker
- Inherits:
-
Object
- Object
- Tasker::Health::StatusChecker
- Defined in:
- lib/tasker/health/status_checker.rb
Overview
StatusChecker provides comprehensive system status information
Gathers detailed metrics about tasks, workflow steps, and system health. Uses Rails caching to avoid expensive database queries on frequent requests.
Constant Summary collapse
- CACHE_KEY =
Cache key for status data
'tasker:health:status'
Instance Attribute Summary collapse
-
#cache_duration ⇒ Integer
readonly
Cache duration in seconds.
Class Method Summary collapse
-
.status ⇒ Hash
Class method for status check.
Instance Method Summary collapse
-
#check(force_refresh: false) ⇒ Hash
Perform comprehensive status check.
-
#initialize(cache_duration: nil) ⇒ StatusChecker
constructor
Initialize status checker.
Constructor Details
#initialize(cache_duration: nil) ⇒ StatusChecker
Initialize status checker
27 28 29 |
# File 'lib/tasker/health/status_checker.rb', line 27 def initialize(cache_duration: nil) @cache_duration = cache_duration || Tasker::Configuration.configuration.health.cache_duration_seconds end |
Instance Attribute Details
#cache_duration ⇒ Integer (readonly)
Returns Cache duration in seconds.
19 20 21 |
# File 'lib/tasker/health/status_checker.rb', line 19 def cache_duration @cache_duration end |
Class Method Details
.status ⇒ Hash
Class method for status check
34 35 36 |
# File 'lib/tasker/health/status_checker.rb', line 34 def self.status new.check end |
Instance Method Details
#check(force_refresh: false) ⇒ Hash
Perform comprehensive status check
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tasker/health/status_checker.rb', line 47 def check(force_refresh: false) if force_refresh result = generate_status_data result[:cached] = false result else begin # Check if we have cached data first cached_data = Rails.cache.read(CACHE_KEY) if cached_data.nil? # No cached data, generate fresh and cache it result = generate_status_data # Create a copy for caching (without the cached flag) cache_data = result.dup cache_data.delete(:cached) Rails.cache.write(CACHE_KEY, cache_data, expires_in: @cache_duration.seconds) result[:cached] = false else # Return cached data with cached flag set result = cached_data.dup result[:cached] = true end result rescue StandardError => e # If cache fails, generate fresh data result = generate_status_data result[:cached] = false result[:cache_error] = "Cache error: #{e.}" result end end end |