Skip to content

Commit 529a740

Browse files
committed
Only send emails after the entire round is done
1 parent e59b68b commit 529a740

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

app/services/execute_ranked_choice_signup_round_service.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,24 @@ def inner_call # rubocop:disable Metrics/MethodLength
3131
return success(decisions: []) if signup_round.maximum_event_signups_as_number <= prev_max_signups
3232

3333
with_relevant_locks do
34+
executed_choices = []
35+
3436
ActiveRecord::Base.transaction do
3537
pass_number = 0
3638
loop do
3739
executed_choices_this_pass = execute_pass(pass_number)
3840
break if executed_choices_this_pass.blank?
41+
42+
executed_choices += executed_choices_this_pass
3943
pass_number += 1
4044
end
4145

4246
ordered_user_con_profiles.update_all(ranked_choice_ordering_boost: 0)
4347
end
4448
end
4549

50+
send_notifications(executed_choices)
51+
4652
success(decisions:)
4753
end
4854

@@ -68,25 +74,20 @@ def ordered_user_con_profiles
6874
def execute_pass(pass_number)
6975
prev_decisions = @decisions.dup
7076

71-
executed_choices =
72-
ActiveRecord::Base.transaction(requires_new: true) do
73-
user_con_profiles = ordered_user_con_profiles.to_a
74-
user_con_profiles.reverse! if signup_round.serpentine_ranked_choice_order? && pass_number.odd?
77+
ActiveRecord::Base.transaction(requires_new: true) do
78+
user_con_profiles = ordered_user_con_profiles.to_a
79+
user_con_profiles.reverse! if signup_round.serpentine_ranked_choice_order? && pass_number.odd?
7580

76-
executed_choices =
77-
user_con_profiles.filter_map { |user_con_profile| execute_choices_for_user_con_profile(user_con_profile) }
81+
executed_choices =
82+
user_con_profiles.filter_map { |user_con_profile| execute_choices_for_user_con_profile(user_con_profile) }
7883

79-
if executed_choices.empty?
80-
@decisions = prev_decisions
81-
raise ActiveRecord::Rollback
82-
end
83-
84-
executed_choices
84+
if executed_choices.empty?
85+
@decisions = prev_decisions
86+
raise ActiveRecord::Rollback
8587
end
8688

87-
send_notifications(executed_choices) if executed_choices
88-
89-
executed_choices
89+
executed_choices
90+
end
9091
end
9192

9293
def execute_choices_for_user_con_profile(user_con_profile)

0 commit comments

Comments
 (0)