Skip to content

Commit 5bfd3ee

Browse files
committed
Add queue configuration for notifications in various notifiers
1 parent 1f5be64 commit 5bfd3ee

File tree

8 files changed

+41
-26
lines changed

8 files changed

+41
-26
lines changed

app/notifiers/better_together/event_invitation_notifier.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,37 @@
22

33
module BetterTogether
44
class EventInvitationNotifier < ApplicationNotifier # rubocop:todo Style/Documentation
5-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message
6-
deliver_by :email, mailer: 'BetterTogether::EventInvitationsMailer', method: :invite, params: :email_params
5+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
6+
queue: :notifications
7+
deliver_by :email, mailer: 'BetterTogether::EventInvitationsMailer', method: :invite, params: :email_params,
8+
queue: :mailers
79

8-
param :invitation
10+
required_param :invitation
911

10-
notification_methods do
11-
def invitation = params[:invitation]
12-
def event = invitation.invitable
12+
def event
13+
params[:invitation].invitable
1314
end
1415

1516
def title
16-
I18n.t('better_together.notifications.event_invitation.title',
17-
event_name: event&.name, default: 'You have been invited to an event')
17+
I18n.with_locale(params[:invitation].locale) do
18+
I18n.t('better_together.notifications.event_invitation.title',
19+
event_name: event&.name, default: 'You have been invited to an event')
20+
end
1821
end
1922

2023
def body
21-
I18n.t('better_together.notifications.event_invitation.body',
22-
event_name: event&.name, default: 'Invitation to %<event_name>s')
24+
I18n.with_locale(params[:invitation].locale) do
25+
I18n.t('better_together.notifications.event_invitation.body',
26+
event_name: event&.name, default: 'Invitation to %<event_name>s')
27+
end
2328
end
2429

2530
def build_message(_notification)
26-
{ title:, body:, url: invitation.url_for_review }
31+
{ title:, body:, url: params[:invitation].url_for_review }
2732
end
2833

2934
def email_params(_notification)
30-
{ invitation: }
35+
params[:invitation]
3136
end
3237
end
3338
end

app/notifiers/better_together/event_reminder_notifier.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
module BetterTogether
44
# Notifies attendees when an event is approaching
55
class EventReminderNotifier < ApplicationNotifier
6-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message do |config|
6+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
7+
queue: :notifications do |config|
78
config.if = -> { should_notify? }
89
end
9-
deliver_by :email, mailer: 'BetterTogether::EventMailer', method: :event_reminder, params: :email_params do |config|
10+
deliver_by :email, mailer: 'BetterTogether::EventMailer', method: :event_reminder, params: :email_params,
11+
queue: :mailers do |config|
1012
config.wait = 15.minutes
1113
config.if = -> { send_email_notification? }
1214
end

app/notifiers/better_together/event_update_notifier.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
module BetterTogether
44
# Notifies attendees when an event is updated
55
class EventUpdateNotifier < ApplicationNotifier
6-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message do |config|
6+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
7+
queue: :notifications do |config|
78
config.if = -> { should_notify? }
89
end
9-
deliver_by :email, mailer: 'BetterTogether::EventMailer', method: :event_update, params: :email_params do |config|
10+
deliver_by :email, mailer: 'BetterTogether::EventMailer', method: :event_update, params: :email_params,
11+
queue: :mailers do |config|
1012
config.if = -> { recipient_has_email? && should_notify? }
1113
end
1214

app/notifiers/better_together/joatu/agreement_notifier.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ module BetterTogether
44
module Joatu
55
# Sends notifications when a new agreement is created
66
class AgreementNotifier < ApplicationNotifier
7-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message
7+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
8+
queue: :notifications
89
deliver_by :email,
910
mailer: 'BetterTogether::JoatuMailer',
1011
method: :agreement_created,
11-
params: :email_params do |config|
12+
params: :email_params, queue: :mailers do |config|
1213
config.if = -> { recipient.email.present? && recipient.notification_preferences['notify_by_email'] }
1314
end
1415

app/notifiers/better_together/joatu/agreement_status_notifier.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ module BetterTogether
44
module Joatu
55
# Notifies offer and request creators when an agreement status changes
66
class AgreementStatusNotifier < ApplicationNotifier
7-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message
7+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
8+
queue: :notifications
89

910
deliver_by :email, mailer: 'BetterTogether::JoatuMailer', method: :agreement_status_changed,
10-
params: :email_params do |config|
11+
params: :email_params, queue: :mailers do |config|
1112
config.if = -> { send_email_notification? }
1213
end
1314

app/notifiers/better_together/joatu/match_notifier.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module BetterTogether
44
module Joatu
55
# Notifies creators when a new offer or request matches
66
class MatchNotifier < ApplicationNotifier
7-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message do |config|
7+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
8+
queue: :notifications do |config|
89
config.if = -> { should_notify? }
910
end
10-
deliver_by :email, mailer: 'BetterTogether::JoatuMailer', method: :new_match, params: :email_params do |config|
11+
deliver_by :email, mailer: 'BetterTogether::JoatuMailer', method: :new_match, params: :email_params,
12+
queue: :mailers do |config|
1113
config.if = -> { recipient_has_email? && should_notify? }
1214
end
1315

app/notifiers/better_together/new_message_notifier.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
module BetterTogether
44
# Uses Noticed gem to create and dispatch notifications for new messages
55
class NewMessageNotifier < ApplicationNotifier
6-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message
6+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
7+
queue: :notifications
78
# deliver_by :action_cable, channel: 'BetterTogether::MessagesChannel', message: :build_message
89
deliver_by :email, mailer: 'BetterTogether::ConversationMailer', method: :new_message_notification,
9-
params: :email_params do |config|
10+
params: :email_params, queue: :mailers do |config|
1011
config.wait = 15.minutes
1112
config.if = -> { send_email_notification? }
1213
end

app/notifiers/better_together/page_authorship_notifier.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
module BetterTogether
44
# Notifies a person when added to or removed from a Page as an author
55
class PageAuthorshipNotifier < ApplicationNotifier
6-
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message
6+
deliver_by :action_cable, channel: 'BetterTogether::NotificationsChannel', message: :build_message,
7+
queue: :notifications
78

89
deliver_by :email,
910
mailer: 'BetterTogether::AuthorshipMailer',
1011
method: :authorship_changed_notification,
11-
params: :email_params do |config|
12+
params: :email_params, queue: :mailers do |config|
1213
config.wait = 15.minutes
1314
config.if = -> { send_email_notification? }
1415
end

0 commit comments

Comments
 (0)