Skip to content

Commit

Permalink
Fix race (#7203)
Browse files Browse the repository at this point in the history
* Fix race

* Add extra guard
  • Loading branch information
iHiD authored Dec 18, 2024
1 parent 3bcafb5 commit 90b46ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/commands/user/bootcamp/subscribe_to_onboarding_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SubscribeToOnboardingEmails

def call
return unless bootcamp_data.enrolled?
return User::Bootcamp::SubscribeToOnboardingEmails.(duplicate) if duplicate

new_sub = add_subscriber!
add_to_form! if new_sub
Expand Down Expand Up @@ -41,13 +42,21 @@ def add_subscriber!

def add_to_form!
RestClient.post(
"https://api.kit.com//v4/forms/#{BOOTCAMP_FORM_ID}/subscribers",
"https://api.kit.com/v4/forms/#{BOOTCAMP_FORM_ID}/subscribers",
{
"email_address": bootcamp_data.email
}, HEADERS
)
end

def duplicate
User::BootcampData.
where(email: bootcamp_data.email).
where.not(id: bootcamp_data.id).
paid.
first
end

HEADERS = {
'Accept': 'application/json',
'X-Kit-Api-Key': Exercism.secrets.key_api4_key
Expand Down
2 changes: 1 addition & 1 deletion app/models/user/bootcamp_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class User::BootcampData < ApplicationRecord
scope :not_enrolled, -> { where(enrolled_at: nil) }
scope :not_paid, -> { where(paid_at: nil) }

after_save do
after_save_commit do
User::Bootcamp::SubscribeToOnboardingEmails.defer(self)
end

Expand Down

0 comments on commit 90b46ce

Please sign in to comment.