Class: EventDrivenWorkers::HhSearch::IndexWorker

Inherits:
ApplicationWorker
  • Object
show all
Defined in:
app/workers/event_driven_workers/hh_search/index_worker.rb

Overview

This worker handles indexing events for different schemas in the HungryHub search service. It uses Sidekiq for background processing and is configured to retry on failure and use the :kafka_hh_indexer queue.

Constants:

  • BATCH_SIZE: The number of records to process in a single batch.

  • EVENT_TYPE: The type of event to trigger for indexing.

Methods:

  • perform(domain): Processes the indexing for the specified domain. The domain can be one of the following:

    • 'restaurants': Reindexes restaurant data.

    • 'restaurant_tags': Reindexes restaurant tag data in batches.

    • 'inventories': Reindexes restaurant availability data (inventories).

    • 'restaurant_with_inventories': Reindexes restaurant data including inventories.

    • Raises an error if the domain is unknown.

Note:

  • “jid” is the global attribute from Sidekiq::Worker, representing the job id.

Constant Summary collapse

BATCH_SIZE =

Adjust the batch size as needed

50
EVENT_TYPE =
EventDrivenClient::Constants::INDEX_EVENT

Instance Method Summary collapse

Instance Method Details

#perform(domain) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/workers/event_driven_workers/hh_search/index_worker.rb', line 28

def perform(domain)
  case domain
  when 'restaurants'
    EventDrivenServices::HhSearch::Producers::RestaurantProducer.new(nil, EVENT_TYPE).
      reindex_all(with_availability: false, batch_id: jid)
  when 'restaurant_tags'
    EventDrivenServices::HhSearch::Producers::RestaurantTagProducer.new(nil, EVENT_TYPE).
      reindex_all(batch_size: BATCH_SIZE, batch_id: jid)
  when 'inventories'
    EventDrivenServices::HhSearch::Producers::Restaurants::AvailabilityProducer.new(
      nil, EventDrivenClient::Constants::UPDATE_EVENT
    ).reindex_all(batch_id: jid)
  when 'restaurant_with_inventories'
    EventDrivenServices::HhSearch::Producers::RestaurantProducer.new(nil, EVENT_TYPE).
      reindex_all(with_availability: true, batch_id: jid)
  else
    raise "Unknown domain: #{domain}"
  end
end