Class: ScheduleWorkers::AutoExtendPackageSubWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ScheduleWorkers::AutoExtendPackageSubWorker
- Defined in:
- app/workers/schedule_workers/auto_extend_package_sub_worker.rb
Instance Method Summary collapse
-
#initialize(kafka_producer: Karafka.producer, opening_hours_worker: HhPackage::GenerateOpeningHoursWorker) ⇒ AutoExtendPackageSubWorker
constructor
Initialize with injectable dependencies for better testability.
-
#perform(restaurant_id) ⇒ Object
Processes auto-extension for a single restaurant's packages.
Methods inherited from ApplicationWorker
Constructor Details
#initialize(kafka_producer: Karafka.producer, opening_hours_worker: HhPackage::GenerateOpeningHoursWorker) ⇒ AutoExtendPackageSubWorker
Initialize with injectable dependencies for better testability
20 21 22 23 24 25 26 |
# File 'app/workers/schedule_workers/auto_extend_package_sub_worker.rb', line 20 def initialize( kafka_producer: Karafka.producer, opening_hours_worker: HhPackage::GenerateOpeningHoursWorker ) @kafka_producer = kafka_producer @opening_hours_worker = opening_hours_worker end |
Instance Method Details
#perform(restaurant_id) ⇒ Object
Processes auto-extension for a single restaurant's packages.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/workers/schedule_workers/auto_extend_package_sub_worker.rb', line 31 def perform(restaurant_id) restaurant = Restaurant.find(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? packages_data = prepare_package_updates(restaurant) if packages_data[:packages_to_update].any? # Perform bulk update for this restaurant's packages bulk_update_packages(packages_data[:packages_to_update]) # Process cache updates for this restaurant batch_process_cache_updates(packages_data[:packages_to_update]) BUSINESS_LOGGER.info( "#{self.class}: Updated packages for restaurant #{restaurant.id}", package_count: packages_data[:packages_to_update].size, new_expiry_date: packages_data[:new_expiry_date], ) 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 |