Class: Vendors::Bistrochat::BlockageWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- Vendors::Bistrochat::BlockageWorker
- Includes:
- DefaultErrorContainer
- Defined in:
- app/workers/vendors/bistrochat/blockage_worker.rb
Instance Method Summary collapse
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Instance Method Details
#perform(blockage_id, reservation_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/workers/vendors/bistrochat/blockage_worker.rb', line 5 def perform(blockage_id, reservation_id) reservation = Reservation.find_by(id: reservation_id) BUSINESS_LOGGER.set_business_context({ reservation_id: reservation_id, blockage_id: blockage_id }) unless reservation # send error to rollbar if reservation not found APMErrorHandler.report("Failed to update blockage: #{self.class} Reservation not found", reservation_id: reservation_id, blockage_id: blockage_id) return end is_vendor_reservation = reservation.by_bistrochat? blockage_service_result = ::Bistrochat::Blockages::Detail.new(blockage_id).show if blockage_service_result.success? if is_vendor_reservation BUSINESS_LOGGER.info("#{self.class}: Blockage is already used by reservation, exiting worker") elsif !is_vendor_reservation BUSINESS_LOGGER.info("#{self.class}: Vendor reservation is not present, but blockage exists, updating expire time of blockage") # update expire time of blockage Bistrochat ::Bistrochat::Blockages::Update.new(blockage_id, reservation.id).execute end # if blockage not exist in Bistrochat, then need to create blockage elsif !blockage_service_result.success? BUSINESS_LOGGER.info("#{self.class}: Blockage not exist in Bistrochat, create blockage") create_blockage_result = create_bistrochat_blockage(reservation) # update blockage_id to InventoryBistrochatBlockage if blockage successfully created # no need to send error to rollbar if blockage not created # because it will be handled by create_bistrochat_blockage if create_blockage_result.success? && create_blockage_result.data.present? blockage_id = create_blockage_result.data[:blockage_id] bistrochat_blockage = InventoryBistrochatBlockage.find_or_initialize_by(reservation_id: reservation.id) bistrochat_blockage.update!(blockage_id: blockage_id) BUSINESS_LOGGER.info("#{self.class}: Blockage successfully created") else = "#{self.class}: Failed to create blockage" BUSINESS_LOGGER.error() APMErrorHandler.report(, reservation_id: reservation_id, blockage_id: blockage_id) end end end |