Class: ScheduleWorkers::AutoExtendInventorySubWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ScheduleWorkers::AutoExtendInventorySubWorker
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb
Constant Summary collapse
- BATCH_SIZE =
Constants for batch processing
1000- DEFAULT_SERVICE_TYPE =
Service type constant
'dine_in'- DAY_MAPPING =
Day mapping constant to avoid recreation on every method call
{ 0 => :sun, 1 => :mon, 2 => :tue, 3 => :wed, 4 => :thu, 5 => :fri, 6 => :sat }.freeze
Instance Attribute Summary collapse
-
#event_worker ⇒ Object
readonly
Dependency injection for better testability.
-
#kafka_producer ⇒ Object
readonly
Dependency injection for better testability.
-
#partner_service ⇒ Object
readonly
Dependency injection for better testability.
-
#reservation_worker ⇒ Object
readonly
Dependency injection for better testability.
Instance Method Summary collapse
-
#initialize(partner_service: PartnerService::Inventories::FetchService, reservation_worker: InventoryReservationWorker, kafka_producer: Karafka.producer, event_worker: EventDrivenWorkers::HhSearch::InventoryProducerWorker) ⇒ AutoExtendInventorySubWorker
constructor
A new instance of AutoExtendInventorySubWorker.
-
#perform(restaurant_id) ⇒ Object
Processes inventory generation for a single restaurant.
Methods inherited from ApplicationWorker
Constructor Details
#initialize(partner_service: PartnerService::Inventories::FetchService, reservation_worker: InventoryReservationWorker, kafka_producer: Karafka.producer, event_worker: EventDrivenWorkers::HhSearch::InventoryProducerWorker) ⇒ AutoExtendInventorySubWorker
Returns a new instance of AutoExtendInventorySubWorker.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 29 def initialize( partner_service: PartnerService::Inventories::FetchService, reservation_worker: InventoryReservationWorker, kafka_producer: Karafka.producer, event_worker: EventDrivenWorkers::HhSearch::InventoryProducerWorker ) super() @partner_service = partner_service @reservation_worker = reservation_worker @kafka_producer = kafka_producer @event_worker = event_worker end |
Instance Attribute Details
#event_worker ⇒ Object (readonly)
Dependency injection for better testability
27 28 29 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 27 def event_worker @event_worker end |
#kafka_producer ⇒ Object (readonly)
Dependency injection for better testability
27 28 29 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 27 def kafka_producer @kafka_producer end |
#partner_service ⇒ Object (readonly)
Dependency injection for better testability
27 28 29 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 27 def partner_service @partner_service end |
#reservation_worker ⇒ Object (readonly)
Dependency injection for better testability
27 28 29 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 27 def reservation_worker @reservation_worker end |
Instance Method Details
#perform(restaurant_id) ⇒ Object
Processes inventory generation for a single restaurant.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/workers/schedule_workers/auto_extend_inventory_sub_worker.rb', line 45 def perform(restaurant_id) restaurant = find_restaurant(restaurant_id) return unless restaurant # Skip if restaurant is not active and not bookable if !restaurant.active && !restaurant.allow_booking BUSINESS_LOGGER.info( "#{self.class}: Skipping restaurant #{restaurant.id} - inactive and not bookable", restaurant_id: restaurant.id, active: restaurant.active, allow_booking: restaurant.allow_booking, ) return end return unless restaurant.bookable_and_not_expired? missing_dates = find_missing_inventory_dates(restaurant) if missing_dates.any? generate_missing_inventory(restaurant, missing_dates) BUSINESS_LOGGER.info( "#{self.class}: Generated missing inventory for restaurant #{restaurant.id}", missing_dates_count: missing_dates.size, ) end rescue ActiveRecord::RecordNotFound BUSINESS_LOGGER.warn( "#{self.class}: Restaurant #{restaurant_id} not found, skipping", ) rescue StandardError => e APMErrorHandler.report(e, context: { restaurant_id: restaurant_id }) raise e end |