@@ -2,14 +2,16 @@ module WorkshopInvitationManagerConcerns
22 extend ActiveSupport ::Concern
33
44 included do
5+ include AsyncEmailConcern
56 include InstanceMethods
67 end
78
89 module InstanceMethods
910 def send_workshop_attendance_reminders ( workshop )
1011 workshop_mailer = workshop . virtual? ? VirtualWorkshopInvitationMailer : WorkshopInvitationMailer
1112 workshop . attendances . not_reminded . each do |invitation |
12- workshop_mailer . send ( :attending_reminder , workshop , invitation . member , invitation ) . deliver_now
13+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
14+ workshop_mailer . send ( :attending_reminder , workshop , invitation . member , invitation ) . public_send ( deliver_method )
1315 invitation . update ( reminded_at : Time . zone . now )
1416 end
1517 end
@@ -86,7 +88,8 @@ def send_waiting_list_emails(workshop)
8688 def send_workshop_waiting_list_reminders ( workshop )
8789 workshop_mailer = workshop . virtual? ? VirtualWorkshopInvitationMailer : WorkshopInvitationMailer
8890 workshop . invitations . on_waiting_list . not_reminded . each do |invitation |
89- workshop_mailer . send ( :waiting_list_reminder , workshop , invitation . member , invitation ) . deliver_now
91+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
92+ workshop_mailer . send ( :waiting_list_reminder , workshop , invitation . member , invitation ) . public_send ( deliver_method )
9093 invitation . update ( reminded_at : Time . zone . now )
9194 end
9295 end
@@ -113,26 +116,30 @@ def log_invitation_failure(workshop, member, role, error)
113116 end
114117
115118 def invite_coaches_to_virtual_workshop ( workshop , logger = nil )
119+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
116120 invite_members ( workshop , logger , chapter_coaches ( workshop . chapter ) ) do |coach , invitation |
117- VirtualWorkshopInvitationMailer . invite_coach ( workshop , coach , invitation ) . deliver_now
121+ VirtualWorkshopInvitationMailer . invite_coach ( workshop , coach , invitation ) . public_send ( deliver_method )
118122 end
119123 end
120124
121125 def invite_coaches_to_workshop ( workshop , logger = nil )
126+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
122127 invite_members ( workshop , logger , chapter_coaches ( workshop . chapter ) ) do |coach , invitation |
123- WorkshopInvitationMailer . invite_coach ( workshop , coach , invitation ) . deliver_now
128+ WorkshopInvitationMailer . invite_coach ( workshop , coach , invitation ) . public_send ( deliver_method )
124129 end
125130 end
126131
127132 def invite_students_to_virtual_workshop ( workshop , logger = nil )
133+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
128134 invite_members ( workshop , logger , chapter_students ( workshop . chapter ) , 'Student' ) do |student , invitation |
129- VirtualWorkshopInvitationMailer . invite_student ( workshop , student , invitation ) . deliver_now
135+ VirtualWorkshopInvitationMailer . invite_student ( workshop , student , invitation ) . public_send ( deliver_method )
130136 end
131137 end
132138
133139 def invite_students_to_workshop ( workshop , logger = nil )
140+ deliver_method = async_email_enabled? ( workshop . chapter ) ? :deliver_later : :deliver_now
134141 invite_members ( workshop , logger , chapter_students ( workshop . chapter ) , 'Student' ) do |member , invitation |
135- WorkshopInvitationMailer . invite_student ( workshop , member , invitation ) . deliver_now
142+ WorkshopInvitationMailer . invite_student ( workshop , member , invitation ) . public_send ( deliver_method )
136143 end
137144 end
138145
@@ -169,7 +176,8 @@ def send_email_with_logging(logger, member, invitation)
169176
170177 def retrieve_and_notify_waitlisted ( workshop , role :)
171178 WaitingList . by_workshop ( workshop ) . where_role ( role ) . each do |waiting_list |
172- WorkshopInvitationMailer . notify_waiting_list ( waiting_list . invitation ) . deliver_now
179+ deliver_method = async_email_enabled? ( waiting_list . invitation . workshop . chapter ) ? :deliver_later : :deliver_now
180+ WorkshopInvitationMailer . notify_waiting_list ( waiting_list . invitation ) . public_send ( deliver_method )
173181 waiting_list . destroy
174182 end
175183 end
0 commit comments