Class: ScheduleWorkers::GoogleReserve::AvailabilityFeedsWorker

Inherits:
ApplicationWorker
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/workers/schedule_workers/google_reserve/availability_feeds_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(mode = 'schedule', restaurant_ids = nil, shard_number = 0, generation_timestamp = nil, retry_count = 0) ⇒ void

This method returns an undefined value.

Main entry point for the availability feed generation process Supports three modes of operation:

  • 'schedule': Deletes all existing data and initiates the distributed processing

  • 'process': Processes a single restaurant (restaurant_ids is single integer)

  • 'upload': Aggregates and uploads a single shard feed (restaurant_ids is array, shard_number required)

Parameters:

  • mode (String) (defaults to: 'schedule')

    The operation mode (default: 'schedule')

  • restaurant_ids (Integer, Array<Integer>) (defaults to: nil)

    Restaurant ID (integer) for 'process' mode, or array of IDs for 'upload' mode

  • shard_number (Integer) (defaults to: 0)

    Shard number for 'upload' mode (default: 0)

  • generation_timestamp (String) (defaults to: nil)

    Timestamp for feed generation consistency across shards (default: nil)

  • retry_count (Integer) (defaults to: 0)

    Retry attempt count for 'upload' mode (default: 0, rare parameter)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/workers/schedule_workers/google_reserve/availability_feeds_worker.rb', line 44

def perform(mode = 'schedule', restaurant_ids = nil, shard_number = 0, generation_timestamp = nil, retry_count = 0)
  return unless Flipper.enabled?(:google_reserve_e2e)

  case mode
  when 'schedule'
    VendorsService::GoogleReserve::AvailabilityFeeds::SchedulerService.new.call
  when 'process'
    # For process mode, restaurant_ids is a single integer (restaurant_id)
    # Extract first element if array is passed (for safety), otherwise use as-is
    restaurant_id = restaurant_ids.is_a?(Array) ? restaurant_ids.first : restaurant_ids
    VendorsService::GoogleReserve::AvailabilityFeeds::ProcessorService.new(restaurant_id).call
  when 'upload'
    # For upload mode, restaurant_ids must be an array of integers
    VendorsService::GoogleReserve::AvailabilityFeeds::UploaderService.new(
      restaurant_ids,
      shard_number,
      generation_timestamp,
      retry_count,
    ).call
  else
    APMErrorHandler.report("#{self.class}: Unknown mode: #{mode}")
  end
end