Skip to content

Commit

Permalink
Retry outbound emails
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed May 27, 2024
1 parent 7b36105 commit 581b1eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/jobs/entry_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class EntryJob < ActiveJob::Base
queue_as :default

retry_on RestClient::Unauthorized, wait: 5.minutes, attempts: 3

def perform(user_id, random_inspiration_id, sent_in_hour)
user = User.find(user_id)
random_inspiration = Inspiration.find(random_inspiration_id)
EntryMailer.send_entry(user, random_inspiration).deliver_now
rescue StandardError => e
Sentry.set_user(id: user.id, email: user.email)
Sentry.set_tags(plan: user.plan)
Sentry.capture_exception(e, extra: { sent_in_hour: sent_in_hour })
raise
end
end
4 changes: 2 additions & 2 deletions lib/tasks/entry.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :entry do
# rake entry:send_entries_test
task :send_entries_test => :environment do
user = User.where(:email=>"[email protected]").first
EntryMailer.send_entry(user, Inspiration.random).deliver_now
EntryJob.perform_later(user.id, Inspiration.random.id, 0)
end

# TRIGGERED MANUALLY
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace :entry do
if user.is_free? && user.emails_sent > 6 && user.entries.count == 0 && ENV['FREE_WEEK'] != 'true'
user.update_columns(frequency: [], previous_frequency: user.frequency)
elsif user.is_pro? || (user.is_free? && Time.now.strftime("%U").to_i % 2 == 0) || ENV['FREE_WEEK'] == 'true' # Every other week for free users
EntryMailer.send_entry(user, random_inspiration).deliver_now
EntryJob.perform_later(user.id, random_inspiration.id, sent_in_hour)
sent_in_hour += 1
end
rescue => error
Expand Down

0 comments on commit 581b1eb

Please sign in to comment.