Class: EventDrivenServices::HhSearch::Producers::RestaurantTagProducer
- Inherits:
-
Object
- Object
- EventDrivenServices::HhSearch::Producers::RestaurantTagProducer
- Includes:
- Helpers::RestaurantTagHelper
- Defined in:
- app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb
Constant Summary collapse
- VALID_EVENT_TYPES =
[ EventDrivenClient::Constants::INDEX_EVENT, EventDrivenClient::Constants::CREATE_EVENT, EventDrivenClient::Constants::UPDATE_EVENT, EventDrivenClient::Constants::DELETE_EVENT, ].freeze
Instance Attribute Summary collapse
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#restaurant_tag ⇒ Object
readonly
Returns the value of attribute restaurant_tag.
-
#restaurant_tag_id ⇒ Object
readonly
Returns the value of attribute restaurant_tag_id.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(restaurant_tag_id, event_type) ⇒ RestaurantTagProducer
constructor
A new instance of RestaurantTagProducer.
- #reindex_all(batch_size: 10, batch_id: nil) ⇒ Object
- #send_event ⇒ Object
Constructor Details
#initialize(restaurant_tag_id, event_type) ⇒ RestaurantTagProducer
Returns a new instance of RestaurantTagProducer.
17 18 19 20 21 22 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 17 def initialize(restaurant_tag_id, event_type) @restaurant_tag_id = restaurant_tag_id @restaurant_tag = RestaurantTag.find_by(id: restaurant_tag_id) if restaurant_tag_id.present? @event_type = validate_event_type(event_type) @topic = EventDrivenClient::Constants::RESTAURANT_TAGS_TOPIC end |
Instance Attribute Details
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
8 9 10 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 8 def event_type @event_type end |
#restaurant_tag ⇒ Object (readonly)
Returns the value of attribute restaurant_tag.
8 9 10 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 8 def restaurant_tag @restaurant_tag end |
#restaurant_tag_id ⇒ Object (readonly)
Returns the value of attribute restaurant_tag_id.
8 9 10 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 8 def restaurant_tag_id @restaurant_tag_id end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
8 9 10 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 8 def topic @topic end |
Instance Method Details
#reindex_all(batch_size: 10, batch_id: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 32 def reindex_all(batch_size: 10, batch_id: nil) batch_number = 1 last_record_id = nil RestaurantTag.find_in_batches(batch_size: batch_size) do |batch| # Check if this is the last batch # If the batch size is less than the requested batch size, or the last record ID is the same as the last record ID in the batch is_last_batch = batch.size < batch_size || (batch.last.id == last_record_id) payload = generate_reindex_payload(batch, RestaurantTag.count, batch_number, is_last_batch, batch_id) client.send_event_async(payload) last_record_id = batch.last.id batch_number += 1 end rescue StandardError => e APMErrorHandler.report('Failed to reindex all restaurant tags', error: e) raise e end |
#send_event ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/services/event_driven_services/hh_search/producers/restaurant_tag_producer.rb', line 24 def send_event payload = generate_payload(restaurant_tag) client.send_event_async(payload) rescue StandardError => e APMErrorHandler.report("Failed to send event to topic #{topic}", error: e) raise e end |