Class: EventDrivenServices::HhSearch::Producers::Restaurants::TagGroupProducer

Inherits:
Object
  • Object
show all
Defined in:
app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb

Constant Summary collapse

VALID_EVENT_TYPES =
[
  EventDrivenClient::Constants::UPDATE_EVENT,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_tag_group_id, event_type, changes_attributes = {}) ⇒ TagGroupProducer

Returns a new instance of TagGroupProducer.



12
13
14
15
16
17
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 12

def initialize(restaurant_tag_group_id, event_type, changes_attributes = {})
  @restaurant_tag_group = RestaurantTagGroup.find_by(id: restaurant_tag_group_id)
  @event_type = validate_event_type(event_type)
  @topic = EventDrivenClient::Constants::RESTAURANTS_TAG_GROUPS_TOPIC
  @changed_attributes = changes_attributes
end

Instance Attribute Details

#changed_attributesObject (readonly)

Returns the value of attribute changed_attributes.



6
7
8
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 6

def changed_attributes
  @changed_attributes
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



6
7
8
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 6

def event_type
  @event_type
end

#restaurant_tag_groupObject (readonly)

Returns the value of attribute restaurant_tag_group.



6
7
8
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 6

def restaurant_tag_group
  @restaurant_tag_group
end

#topicObject (readonly)

Returns the value of attribute topic.



6
7
8
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 6

def topic
  @topic
end

Instance Method Details

#send_eventObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/event_driven_services/hh_search/producers/restaurants/tag_group_producer.rb', line 19

def send_event
  payload = if event_type == EventDrivenClient::Constants::UPDATE_EVENT
              generate_update_payload(restaurant_tag_group)
            else
              raise NotImplementedError, "Invalid event type: #{event_type}"
            end

  client.send_event_async(payload)
rescue StandardError => e
  APMErrorHandler.report("Failed to send event to topic #{topic}", error: e)
  raise e
end