Module: NotificationWorkers::ReservationModules::BookingModification

Included in:
NotificationWorkers::Reservation
Defined in:
app/workers/notification_workers/reservation_modules/booking_modification.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#notif_booking_modification_by_email(rules) ⇒ 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
47
48
49
50
51
52
# File 'app/workers/notification_workers/reservation_modules/booking_modification.rb', line 5

def notif_booking_modification_by_email(rules)
  # Add comprehensive tracking for booking modification notification
  ElasticAPM.with_span('BookingModification#notif_booking_modification_by_email', 'worker') do
    # Validate reservation exists
    if reservation.nil?
      error_context = {
        rules: rules,
        reservation_present: false,
        caller_stack: capture_stack_trace(5),
      }

      APMErrorHandler.report(
        'BookingModification worker called with nil reservation',
        context: error_context,
        handled: true,
      )

      report["#{__callee__}_to_user"] = 'ERROR: nil reservation'
      return 
    end

    # Validate reservation has an ID
    if reservation.id.nil?
      error_context = {
        rules: rules,
        reservation_present: reservation.present?,
        reservation_class: reservation.class.name,
        reservation_attributes: reservation.attributes.slice('id', 'created_at', 'updated_at'),
        caller_stack: capture_stack_trace(5),
      }

      APMErrorHandler.report(
        'BookingModification worker called with reservation without ID',
        context: error_context,
        handled: true,
      )
      report["#{__callee__}_to_user"] = 'ERROR: reservation without ID'
      return
    end

    # Send to user
    if allow_send_notif_to_user?(receivers: rules[:receiver])
      report["#{__callee__}_to_user"] = safe_call do
        UserMailer.booking_modification(reservation.id, reservation.user_id).deliver_later!
      end
    end
  end
end