Class: ScheduleWorkers::AutoExtendInventoryMainWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ScheduleWorkers::AutoExtendInventoryMainWorker
- Defined in:
- app/workers/schedule_workers/auto_extend_inventory_main_worker.rb
Overview
We don't have “auto-extend” attribute on the Restaurant model. Instead, we have it on the RestaurantPackage model. So the auto-extend logic is based on whether the restaurant is not expired and `accept_booking` is true. No need to check for package model. Because there are some restaurant ID on production that have no package But need to have their inventory auto-extended. Requested by operation team in Slack.
Instance Method Summary collapse
-
#perform ⇒ Object
Dispatches restaurant processing to sub-workers for parallel execution.
Methods inherited from ApplicationWorker
Instance Method Details
#perform ⇒ Object
Dispatches restaurant processing to sub-workers for parallel execution. No input parameters. All operations are performed as a scheduled background job.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/workers/schedule_workers/auto_extend_inventory_main_worker.rb', line 16 def perform restaurant_ids = [] # We extend all types of restaurant. Regardless of whether a restaurant has # a package or not. As long as it has future expiry date and accepts booking, # we should extend its inventory. Restaurant.with_auto_extend_inventories.find_each(batch_size: 10) do |restaurant| restaurant_ids << restaurant.id # Use perform_in with random delay (0-5 minutes) to spread the load delay_seconds = rand(0..300) AutoExtendInventorySubWorker.perform_in(delay_seconds, restaurant.id) end BUSINESS_LOGGER.info( "#{self.class}: Dispatched #{restaurant_ids.size} restaurants for inventory generation", restaurant_ids: restaurant_ids, ) end |