Class: Katello::EventDaemon::Monitor

Inherits:
Object
  • Object
show all
Defined in:
app/lib/katello/event_daemon/monitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(services) ⇒ Monitor

Returns a new instance of Monitor.



4
5
6
7
8
9
10
# File 'app/lib/katello/event_daemon/monitor.rb', line 4

def initialize(services)
  @services = services
  @service_statuses = {}
  @services.keys.each do |service_name|
    @service_statuses[service_name] = { running: 'starting' }
  end
end

Instance Method Details

#check_servicesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/lib/katello/event_daemon/monitor.rb', line 29

def check_services
  @services.each do |service_name, service_class|
    @service_statuses[service_name] = service_class.status
  rescue => error
    Rails.logger.error("Error occurred while pinging #{service_class}")
    Rails.logger.error(error.message)
    Rails.logger.error(error.backtrace.join("\n"))
  ensure
    if error || !@service_statuses.dig(service_name, :running)
      begin
        service_class.close
        service_class.run
        sleep 0.1
        @service_statuses[service_name] = service_class.status
      rescue => error
        Rails.logger.error("Error occurred while starting #{service_class}")
        Rails.logger.error(error.message)
        Rails.logger.error(error.backtrace.join("\n"))
      end
    end
  end
  write_statuses_to_cache
end

#startObject



12
13
14
15
16
17
18
19
20
# File 'app/lib/katello/event_daemon/monitor.rb', line 12

def start
  write_statuses_to_cache
  loop do
    Rails.application.executor.wrap do
      check_services
    end
    sleep 15
  end
end

#write_statuses_to_cacheObject



22
23
24
25
26
27
# File 'app/lib/katello/event_daemon/monitor.rb', line 22

def write_statuses_to_cache
  Rails.cache.write(
    Katello::EventDaemon::Runner::STATUS_CACHE_KEY,
    @service_statuses
  )
end