Class: NotificationSenders::BaseNotificationSender

Inherits:
Object
  • Object
show all
Defined in:
app/notifications/notification_senders/base_notification_sender.rb

Direct Known Subclasses

EmailNotificationSender

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_notification_configuration:, reference_event:, recipient:) ⇒ BaseNotificationSender

Returns a new instance of BaseNotificationSender.



5
6
7
8
9
10
11
12
13
# File 'app/notifications/notification_senders/base_notification_sender.rb', line 5

def initialize(
  event_notification_configuration:,
  reference_event:,
  recipient:
)
  @event_notification_configuration = event_notification_configuration
  @reference_event = reference_event
  @recipient = recipient
end

Instance Attribute Details

#event_notification_configurationObject (readonly)

Returns the value of attribute event_notification_configuration.



3
4
5
# File 'app/notifications/notification_senders/base_notification_sender.rb', line 3

def event_notification_configuration
  @event_notification_configuration
end

#recipientObject (readonly)

Returns the value of attribute recipient.



3
4
5
# File 'app/notifications/notification_senders/base_notification_sender.rb', line 3

def recipient
  @recipient
end

#reference_eventObject (readonly)

Returns the value of attribute reference_event.



3
4
5
# File 'app/notifications/notification_senders/base_notification_sender.rb', line 3

def reference_event
  @reference_event
end

Instance Method Details

#notification_deliveryObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/notifications/notification_senders/base_notification_sender.rb', line 15

def notification_delivery
  # creating the delivery record before sending the notification
  # because we want to have a record of the delivery even if the notification fails
  # or if the notification is sent asynchronously
  # so that another notification is not sent for the same event.
  # If we receive lot of failures or fore more complex scenarios we can add a retry mechanism + a status field
  delivery = EventNotificationDelivery.create!(
    event_notification_configuration: event_notification_configuration,
    recipient: recipient,
    reference_event: reference_event,
    delivered_at: Time.zone.now
  )
  send_notification
  delivery
end