Class: NotificationWorkers::Reservation

Overview

Responsible to send any notifications related to reservation

istilah2 ack = acknowledged / sudah di ketahui/konfirmasi has offers = resto yg punya package confirmed = jika ack == true, maka otomatis confirmed, jika false, maka unconfirmed

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NotificationWorkers::ReservationModules::WaitingForPayment

#has_offers_and_waiting_for_payment_by_email, #has_offers_and_waiting_for_payment_by_sms

Methods included from NotificationWorkers::ReservationModules::PushNotification

#push_notification_booking_cancelled, #push_notification_booking_confirmed, #push_notification_booking_created, #push_notification_booking_modified

Methods included from NotificationWorkers::ReservationModules::BookingConfirmation

#no_ack_has_offers_notif_rejected_by_email, #no_ack_has_offers_notif_rejected_by_sms

Methods included from NotificationWorkers::ReservationModules::BookingCancellation

#alert_booking_cancellation_by_email, #notif_booking_cancellation_by_email, #notif_booking_cancellation_by_sms

Methods included from NotificationWorkers::ReservationModules::BookingModification

#notif_booking_modification_by_email

Methods included from NotificationWorkers::ReservationModules::GroupBooking

#group_booking?, #no_ack_group_booking_notif_by_email, #no_ack_group_booking_notif_by_sms, #not_group_booking?

Methods included from NotificationWorkers::ReservationModules::AdminCreateBooking

#notif_booking_created_by_manual_through_sms

Methods included from NotificationWorkers::ReservationModules::UserMadeNoPackageBookingAckFalse

#no_ack_no_offers_notif_unconfirmed_by_email, #no_ack_no_offers_notif_unconfirmed_by_sms

Methods included from NotificationWorkers::ReservationModules::UserMadePackageBookingAckFalse

#no_ack_notif_unconfirmed_by_email, #no_ack_notif_unconfirmed_by_sms

Methods included from NotificationWorkers::ReservationModules::UserMadePackageBookingAckTrue

#ack_has_offers_ask_to_give_rating_by_email, #ack_has_offers_notif_confirmed_by_email, #ack_has_offers_notif_confirmed_by_sms, #ack_has_offers_notif_last_minute_by_sms

Methods included from NotificationWorkers::ReservationModules::SharedMethods

#ack?, #after_dining_time?, #allow_send_notif_to_user?, #before_dining_time?, #create_gcal_event, #gcal, #gcal_normalized_data, #has_no_packages?, #has_packages?, #manual_booking?, #no_ack?, #no_offers?, #not_last_minute?, #not_manual_booking?, #not_temporary?, #not_waiting_for_payment?, #offers?, #reached_goal?, #sms_admin_no_ack_notifier, #sms_admin_notifier, #sms_owner_notifier, #sms_user_notifier, #waiting_for_payment?

Methods inherited from ApplicationWorker

unlimited_retry

Instance Attribute Details

#notification_pathsObject (readonly)

Returns the value of attribute notification_paths.



29
30
31
# File 'app/workers/notification_workers/reservation.rb', line 29

def notification_paths
  @notification_paths
end

#reservationObject

Returns the value of attribute reservation.



28
29
30
# File 'app/workers/notification_workers/reservation.rb', line 28

def reservation
  @reservation
end

#stateObject

Returns the value of attribute state.



28
29
30
# File 'app/workers/notification_workers/reservation.rb', line 28

def state
  @state
end

Instance Method Details

#perform(id, state) ⇒ Object

Parameters:

  • id (Integer)

    Reservation ID

  • state (String)

    cancel, create, etc



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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/workers/notification_workers/reservation.rb', line 36

def perform(id, state)
  # Add comprehensive tracking for notification worker
  ElasticAPM.with_span('NotificationWorkers::Reservation#perform', 'worker') do
    begin
      # Validate reservation ID parameter
      if id.nil?
        error_context = {
          reservation_id: id,
          state: state,
          caller_stack: Rails.backtrace_cleaner.clean(caller),
        }

        APMErrorHandler.report(
          'NotificationWorkers::Reservation#perform called with nil reservation_id',
          context: error_context,
          handled: true,
        )
        return
      end

      @reservation = ::Reservation.find(id)
      @state = state
      @notification_paths = []
    rescue ActiveRecord::RecordNotFound => e
      # Enhanced error handling for reservation not found
      error_context = {
        reservation_id: id,
        state: state,
        caller_stack: Rails.backtrace_cleaner.clean(caller),
        error_message: e.message,
      }

      APMErrorHandler.report(
        'Reservation not found in NotificationWorkers::Reservation#perform',
        exception: e,
        context: error_context,
        handled: true,
      )

      return
    rescue StandardError => e
      # Catch any other unexpected errors during initialization
      error_context = {
        reservation_id: id,
        state: state,
        caller_stack: Rails.backtrace_cleaner.clean(caller),
      }

      APMErrorHandler.report(
        'Unexpected error during NotificationWorkers::Reservation#perform initialization',
        exception: e,
        context: error_context,
        handled: false,
      )

      raise e # Re-raise unexpected errors
    end

    # Continue with the original notification logic
    if triggered_by.blank?
      APMErrorHandler.report('unknown who triggered notification', {
                               id: id, state: state
                             })
      return
    end

    send_notifications
    .note["notifications_#{.key_suffix}"] = report
    .note["notification_paths_#{.key_suffix}"] = notification_paths

    unless .save
      APMErrorHandler.report('failed to send notifications to users')
    end
  end
end