Class: Katello::CandlepinEventListener

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/candlepin_event_listener.rb

Overview

TODO: Move this class to app/lib/katello/event_daemon/services with other service definitions

Defined Under Namespace

Classes: Event

Class Method Summary collapse

Class Method Details

.closeObject



19
20
21
22
23
24
# File 'app/services/katello/candlepin_event_listener.rb', line 19

def self.close
  if @client&.close
    logger.info("Closed candlepin event listener")
  end
  reset
end

.handle_message(message) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/services/katello/candlepin_event_listener.rb', line 47

def self.handle_message(message)
  ::Katello::Util::Support.with_db_connection(logger) do
    subject = "#{message.headers['EVENT_TARGET']}.#{message.headers['EVENT_TYPE']}".downcase
    cp_event = Event.new(subject, message.body)
    ::Katello::Candlepin::EventHandler.new(logger).handle(cp_event)
  end
  @processed_count += 1
rescue => e
  @failed_count += 1
  logger.error("Error handling Candlepin event")
  logger.error(e.message)
  logger.error(e.backtrace.join("\n"))
end

.loggerObject



11
12
13
# File 'app/services/katello/candlepin_event_listener.rb', line 11

def self.logger
  ::Foreman::Logging.logger('katello/candlepin_events')
end

.resetObject



26
27
28
29
30
# File 'app/services/katello/candlepin_event_listener.rb', line 26

def self.reset
  @processed_count = 0
  @failed_count = 0
  @client = nil
end

.runObject



32
33
34
35
36
37
# File 'app/services/katello/candlepin_event_listener.rb', line 32

def self.run
  @client = client_factory.call
  @client.subscribe do |message|
    handle_message(message)
  end
end

.running?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/services/katello/candlepin_event_listener.rb', line 15

def self.running?
  @client&.running? || false
end

.statusObject



39
40
41
42
43
44
45
# File 'app/services/katello/candlepin_event_listener.rb', line 39

def self.status
  {
    processed_count: @processed_count,
    failed_count: @failed_count,
    running: running?
  }
end