Class: EventDrivenServices::HhSearch::Producers::Restaurants::TagProducer
- Inherits:
-
Object
- Object
- EventDrivenServices::HhSearch::Producers::Restaurants::TagProducer
- Defined in:
- app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb
Constant Summary collapse
- VALID_EVENT_TYPES =
[ EventDrivenClient::Constants::UPDATE_EVENT, ].freeze
Instance Attribute Summary collapse
-
#changed_attributes ⇒ Object
readonly
Returns the value of attribute changed_attributes.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#restaurant_tag ⇒ Object
readonly
Returns the value of attribute restaurant_tag.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(restaurant_tag_id, event_type, changes_attributes = {}) ⇒ TagProducer
constructor
A new instance of TagProducer.
- #send_event ⇒ Object
-
#send_total_restaurants_event ⇒ Object
This method is used to update the total_restaurants of the restaurant tag If there is a new restaurant added to the tag or removed from the tag.
Constructor Details
#initialize(restaurant_tag_id, event_type, changes_attributes = {}) ⇒ TagProducer
Returns a new instance of TagProducer.
12 13 14 15 16 17 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 12 def initialize(restaurant_tag_id, event_type, changes_attributes = {}) @restaurant_tag = RestaurantTag.find_by(id: restaurant_tag_id) @event_type = validate_event_type(event_type) @topic = EventDrivenClient::Constants::RESTAURANTS_TAGS_TOPIC @changed_attributes = changes_attributes end |
Instance Attribute Details
#changed_attributes ⇒ Object (readonly)
Returns the value of attribute changed_attributes.
6 7 8 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 6 def changed_attributes @changed_attributes end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
6 7 8 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 6 def event_type @event_type end |
#restaurant_tag ⇒ Object (readonly)
Returns the value of attribute restaurant_tag.
6 7 8 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 6 def restaurant_tag @restaurant_tag end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
6 7 8 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 6 def topic @topic end |
Instance Method Details
#send_event ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 19 def send_event # No need to send event if there is no changes return if changed_attributes.blank? return if changed_attributes[:add].blank? && changed_attributes[:remove].blank? payload = if event_type == EventDrivenClient::Constants::UPDATE_EVENT generate_update_payload(restaurant_tag) else raise NotImplementedError, "Invalid event type: #{event_type}" end client.send_event_async(payload) send_total_restaurants_event rescue StandardError => e APMErrorHandler.report("Failed to send event to topic #{topic}", error: e) raise e end |
#send_total_restaurants_event ⇒ Object
This method is used to update the total_restaurants of the restaurant tag If there is a new restaurant added to the tag or removed from the tag
41 42 43 44 45 46 47 48 |
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_producer.rb', line 41 def send_total_restaurants_event producer = EventDrivenServices::HhSearch::Producers::RestaurantTagProducer.new( restaurant_tag.id, EventDrivenClient::Constants::UPDATE_EVENT, ) producer.send_event end |