Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions app/models/concerns/async_email_concern.rb

This file was deleted.

22 changes: 7 additions & 15 deletions app/models/concerns/workshop_invitation_manager_concerns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ module WorkshopInvitationManagerConcerns
extend ActiveSupport::Concern

included do
include AsyncEmailConcern
include InstanceMethods
end

module InstanceMethods
def send_workshop_attendance_reminders(workshop)
workshop_mailer = workshop.virtual? ? VirtualWorkshopInvitationMailer : WorkshopInvitationMailer
workshop.attendances.not_reminded.each do |invitation|
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
workshop_mailer.send(:attending_reminder, workshop, invitation.member, invitation).public_send(deliver_method)
workshop_mailer.send(:attending_reminder, workshop, invitation.member, invitation).deliver_later
invitation.update(reminded_at: Time.zone.now)
end
end
Expand Down Expand Up @@ -88,8 +86,7 @@ def send_waiting_list_emails(workshop)
def send_workshop_waiting_list_reminders(workshop)
workshop_mailer = workshop.virtual? ? VirtualWorkshopInvitationMailer : WorkshopInvitationMailer
workshop.invitations.on_waiting_list.not_reminded.each do |invitation|
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
workshop_mailer.send(:waiting_list_reminder, workshop, invitation.member, invitation).public_send(deliver_method)
workshop_mailer.send(:waiting_list_reminder, workshop, invitation.member, invitation).deliver_later
invitation.update(reminded_at: Time.zone.now)
end
end
Expand All @@ -116,30 +113,26 @@ def log_invitation_failure(workshop, member, role, error)
end

def invite_coaches_to_virtual_workshop(workshop, logger = nil)
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
invite_members(workshop, logger, chapter_coaches(workshop.chapter)) do |coach, invitation|
VirtualWorkshopInvitationMailer.invite_coach(workshop, coach, invitation).public_send(deliver_method)
VirtualWorkshopInvitationMailer.invite_coach(workshop, coach, invitation).deliver_later
end
end

def invite_coaches_to_workshop(workshop, logger = nil)
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
invite_members(workshop, logger, chapter_coaches(workshop.chapter)) do |coach, invitation|
WorkshopInvitationMailer.invite_coach(workshop, coach, invitation).public_send(deliver_method)
WorkshopInvitationMailer.invite_coach(workshop, coach, invitation).deliver_later
end
end

def invite_students_to_virtual_workshop(workshop, logger = nil)
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
invite_members(workshop, logger, chapter_students(workshop.chapter), 'Student') do |student, invitation|
VirtualWorkshopInvitationMailer.invite_student(workshop, student, invitation).public_send(deliver_method)
VirtualWorkshopInvitationMailer.invite_student(workshop, student, invitation).deliver_later
end
end

def invite_students_to_workshop(workshop, logger = nil)
deliver_method = async_email_enabled?(workshop.chapter) ? :deliver_later : :deliver_now
invite_members(workshop, logger, chapter_students(workshop.chapter), 'Student') do |member, invitation|
WorkshopInvitationMailer.invite_student(workshop, member, invitation).public_send(deliver_method)
WorkshopInvitationMailer.invite_student(workshop, member, invitation).deliver_later
end
end

Expand Down Expand Up @@ -176,8 +169,7 @@ def send_email_with_logging(logger, member, invitation)

def retrieve_and_notify_waitlisted(workshop, role:)
WaitingList.by_workshop(workshop).where_role(role).each do |waiting_list|
deliver_method = async_email_enabled?(waiting_list.invitation.workshop.chapter) ? :deliver_later : :deliver_now
WorkshopInvitationMailer.notify_waiting_list(waiting_list.invitation).public_send(deliver_method)
WorkshopInvitationMailer.notify_waiting_list(waiting_list.invitation).deliver_later
waiting_list.destroy
end
end
Expand Down
6 changes: 0 additions & 6 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class Application < Rails::Application
# ActiveJob adapter for async email delivery
config.active_job.queue_adapter = :delayed_job

# Feature flag: chapters that use async email delivery
# Empty = no chapters use async (all sync)
# "1" = only chapter 1 uses async
# "1,7" = chapters 1 and 7 use async
config.async_email_chapter_ids = ENV['ASYNC_EMAIL_CHAPTER_IDS']&.split(',')&.map(&:to_i) || []

if ENV["RAILS_LOG_TO_STDOUT"].present?
$stdout.sync = true
config.rails_semantic_logger.add_file_appender = false
Expand Down
34 changes: 0 additions & 34 deletions spec/models/concerns/async_email_concern_spec.rb

This file was deleted.

82 changes: 14 additions & 68 deletions spec/models/invitation_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,80 +360,26 @@
end
end

describe '#send_workshop_emails async behavior' do
let!(:chapter) { Fabricate(:chapter, id: 1) }

context 'when chapter is in ASYNC_EMAIL_CHAPTER_IDS' do
before { Rails.application.config.async_email_chapter_ids = [1] }

it 'sends invitation emails' do
Fabricate(:students, chapter: chapter, members: students)
Fabricate(:coaches, chapter: chapter, members: coaches)

expect {
manager.send_workshop_emails_without_delay(workshop, 'everyone')
}.to change { ActionMailer::Base.deliveries.count }.by(students.count + coaches.count)
end
end

context 'when chapter is NOT in ASYNC_EMAIL_CHAPTER_IDS' do
before { Rails.application.config.async_email_chapter_ids = [99] }

it 'sends emails synchronously' do
Fabricate(:students, chapter: chapter, members: students)
Fabricate(:coaches, chapter: chapter, members: coaches)

expect do
manager.send_workshop_emails(workshop, 'everyone')
end.to change { ActionMailer::Base.deliveries.count }.by(students.count + coaches.count)

expect(Delayed::Job.count).to eq(0)
end
end

context 'when ASYNC_EMAIL_CHAPTER_IDS is empty' do
before { Rails.application.config.async_email_chapter_ids = [] }

it 'sends emails synchronously' do
Fabricate(:students, chapter: chapter, members: students)
Fabricate(:coaches, chapter: chapter, members: coaches)

expect do
manager.send_workshop_emails(workshop, 'everyone')
end.to change { ActionMailer::Base.deliveries.count }.by(students.count + coaches.count)
describe '#send_workshop_emails async delivery' do
it 'sends invitation emails asynchronously for all chapters' do
Fabricate(:students, chapter: chapter, members: students)
Fabricate(:coaches, chapter: chapter, members: coaches)

expect(Delayed::Job.count).to eq(0)
end
expect {
manager.send_workshop_emails_without_delay(workshop, 'everyone')
}.to change { ActionMailer::Base.deliveries.count }.by(students.count + coaches.count)
end
end

describe '#send_workshop_attendance_reminders async behavior' do
let!(:chapter) { Fabricate(:chapter, id: 1) }

context 'when chapter is in ASYNC_EMAIL_CHAPTER_IDS' do
before { Rails.application.config.async_email_chapter_ids = [1] }

it 'sends attendance reminder emails' do
invitation = Fabricate(:attending_workshop_invitation, workshop: workshop)

expect {
manager.send_workshop_attendance_reminders_without_delay(workshop)
}.to change { ActionMailer::Base.deliveries.count }.by(1)

expect(invitation.reload.reminded_at).not_to be_nil
end
end
describe '#send_workshop_attendance_reminders async delivery' do
it 'sends attendance reminder emails asynchronously for all chapters' do
invitation = Fabricate(:attending_workshop_invitation, workshop: workshop)

context 'when chapter is NOT in ASYNC_EMAIL_CHAPTER_IDS' do
before { Rails.application.config.async_email_chapter_ids = [99] }

it 'uses deliver_now' do
invitation = Fabricate(:attending_workshop_invitation, workshop: workshop)
expect {
manager.send_workshop_attendance_reminders_without_delay(workshop)
}.to change { ActionMailer::Base.deliveries.count }.by(1)

expect do
manager.send_workshop_attendance_reminders(workshop)
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end
expect(invitation.reload.reminded_at).not_to be_nil
end
end
end