Module: RedisHealthChecker

Defined in:
lib/admin/redis_health_checker.rb

Class Method Summary collapse

Class Method Details

.app_data_redis_upObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/admin/redis_health_checker.rb', line 8

def self.app_data_redis_up
  Thread.current[:app_data_redis_up] ||= begin
    # Test 1: Check attribute that uses redis key
    session = Session.find_or_build('fake token')
    session.update(uuid: '1234')
    Session.delete('fake token')
    session.present?
  rescue => e
    Rails.logger.error(
      { message: "ARGO CD UPGRADE - REDIS TEST: Failed to access app data Redis. Error: #{e.message}" }
    )
    false
  end
end

.rails_cache_upObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/admin/redis_health_checker.rb', line 23

def self.rails_cache_up
  Thread.current[:rails_cache_up] ||= begin
    # Test 2: Check Rails cache Redis
    Rails.cache.write('test_key', 'test_value')
    result = Rails.cache.read('test_key')
    Rails.cache.delete('test_key')
    result == 'test_value'
  rescue => e
    Rails.logger.error(
      { message: "ARGO CD UPGRADE - REDIS TEST: Failed to access Rails cache Redis. Error: #{e.message}" }
    )
    false
  end
end

.redis_upObject



4
5
6
# File 'lib/admin/redis_health_checker.rb', line 4

def self.redis_up
  app_data_redis_up && rails_cache_up && sidekiq_redis_up
end

.sidekiq_redis_upObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/admin/redis_health_checker.rb', line 38

def self.sidekiq_redis_up
  Thread.current[:sidekiq_redis_up] ||= begin
    # Test 3: Check Sidekiq Redis
    Sidekiq.redis do |conn|
      conn.set('test_key', 'test_value')
      result = conn.get('test_key')
      conn.del('test_key')
      result == 'test_value'
    end
  rescue => e
    Rails.logger.error(
      { message: "ARGO CD UPGRADE - REDIS TEST: Failed to access Sidekiq Redis. Error: #{e.message}" }
    )
    false
  end
end