Class: ScheduleWorkers::GoogleReserve::MonthlyTop3RestaurantPackage
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ScheduleWorkers::GoogleReserve::MonthlyTop3RestaurantPackage
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/workers/schedule_workers/google_reserve/monthly_top3_restaurant_package.rb
Overview
Only processes restaurants that are active, not expired, and have Google Reserve E2E enabled
Manages Google Reserve top-3 packages for restaurants with automatic package selection. Rebuilds packages by deleting existing ones and creating new ones based on current rankings.
Instance Method Summary collapse
-
#perform(restaurant_ids = nil) ⇒ void
Processes or reschedules top-3 package refresh for restaurants.
Instance Method Details
#perform(restaurant_ids = nil) ⇒ void
This method returns an undefined value.
Processes or reschedules top-3 package refresh for restaurants. With exactly 1 eligible restaurant ID, processes directly. With 0 or multiple IDs, reschedules separate jobs for each eligible restaurant.
The worker is tolerant about the shape of `restaurant_ids`:
-
`nil` or empty -> process all eligible restaurants
-
a single Integer/String -> coerced to `[id]` and processed/rescheduled
-
an Array of ids -> processed/rescheduled as provided
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/workers/schedule_workers/google_reserve/monthly_top3_restaurant_package.rb', line 26 def perform(restaurant_ids = nil) # Ensure `restaurant_ids` is an Array or nil (when no specific ids provided) restaurant_ids = Array(restaurant_ids).presence # Always get eligible restaurants to ensure we only process active ones eligible_restaurants = if restaurant_ids active_restaurants.where(id: restaurant_ids) else active_restaurants end # If we have exactly 1 restaurant ID in the INPUT and it's eligible, process it directly # Otherwise, reschedule separate jobs for each eligible restaurant if restaurant_ids&.size == 1 && eligible_restaurants.count == 1 process_restaurant(eligible_restaurants.first) else # Reschedule separate jobs for each eligible restaurant eligible_restaurants.pluck(:id).each do |restaurant_id| self.class.perform_async([restaurant_id]) end end rescue StandardError => e APMErrorHandler.report( e, context: { restaurant_ids: restaurant_ids, worker: self.class.name, operation: 'perform', }, ) raise e end |