Class: Katello::Candlepin::MessageHandler
- Inherits:
-
Object
- Object
- Katello::Candlepin::MessageHandler
- Defined in:
- app/services/katello/candlepin/message_handler.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
-
#pool ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
-
#subscription_facet ⇒ Object
readonly
Service to handle parsing the messages we receive from candlepin.
Instance Method Summary collapse
- #consumer_uuid ⇒ Object
- #content ⇒ Object
- #delete_pool ⇒ Object
- #entity_id ⇒ Object
- #event_data ⇒ Object
- #import_pool(index_hosts = true) ⇒ Object
-
#initialize(message) ⇒ MessageHandler
constructor
A new instance of MessageHandler.
- #pool_id ⇒ Object
- #reasons ⇒ Object
- #status ⇒ Object
- #subject ⇒ Object
- #target_name ⇒ Object
Constructor Details
#initialize(message) ⇒ MessageHandler
Returns a new instance of MessageHandler.
7 8 9 10 11 |
# File 'app/services/katello/candlepin/message_handler.rb', line 7 def initialize() @message = @subscription_facet = ::Katello::Host::SubscriptionFacet.find_by_uuid(consumer_uuid) if consumer_uuid @pool = ::Katello::Pool.find_by_cp_id(pool_id) if pool_id end |
Instance Attribute Details
#message ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def @message end |
#pool ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def pool @pool end |
#subscription_facet ⇒ Object (readonly)
Service to handle parsing the messages we receive from candlepin
5 6 7 |
# File 'app/services/katello/candlepin/message_handler.rb', line 5 def subscription_facet @subscription_facet end |
Instance Method Details
#consumer_uuid ⇒ Object
41 42 43 |
# File 'app/services/katello/candlepin/message_handler.rb', line 41 def consumer_uuid content['consumerUuid'] end |
#content ⇒ Object
17 18 19 |
# File 'app/services/katello/candlepin/message_handler.rb', line 17 def content @content ||= JSON.parse(.content) end |
#delete_pool ⇒ Object
66 67 68 69 70 |
# File 'app/services/katello/candlepin/message_handler.rb', line 66 def delete_pool if Katello::Pool.where(:cp_id => pool_id).destroy_all.any? Rails.logger.info "Deleted Katello::Pool with cp_id=#{pool_id}" end end |
#entity_id ⇒ Object
25 26 27 |
# File 'app/services/katello/candlepin/message_handler.rb', line 25 def entity_id content['entityId'] end |
#event_data ⇒ Object
21 22 23 |
# File 'app/services/katello/candlepin/message_handler.rb', line 21 def event_data @event_data ||= (data = content['eventData']) ? JSON.parse(data) : {} end |
#import_pool(index_hosts = true) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/katello/candlepin/message_handler.rb', line 52 def import_pool(index_hosts = true) if pool ::Katello::EventQueue.push_event(::Katello::Events::ImportPool::EVENT_TYPE, pool.id) else begin ::Katello::Pool.import_pool(pool_id, index_hosts) rescue ActiveRecord::RecordInvalid # if we hit this block it's likely that the pool's subscription, product are being created # as a result of manifest import/refresh or custom product creation Rails.logger.warn("Unable to import pool. It will likely be created by another process.") end end end |
#pool_id ⇒ Object
45 46 47 48 49 50 |
# File 'app/services/katello/candlepin/message_handler.rb', line 45 def pool_id case subject when 'pool.created', 'pool.deleted' content['entityId'] end end |
#reasons ⇒ Object
37 38 39 |
# File 'app/services/katello/candlepin/message_handler.rb', line 37 def reasons event_data['reasons'] end |
#status ⇒ Object
33 34 35 |
# File 'app/services/katello/candlepin/message_handler.rb', line 33 def status event_data['status'] end |
#subject ⇒ Object
13 14 15 |
# File 'app/services/katello/candlepin/message_handler.rb', line 13 def subject @message.subject end |
#target_name ⇒ Object
29 30 31 |
# File 'app/services/katello/candlepin/message_handler.rb', line 29 def target_name content['targetName'] end |