Skip to content

Commit

Permalink
Expire jobs on failure (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdavidhamilton authored May 22, 2024
1 parent 12f481c commit d3a3d5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def run(*)
log 'running'

if duplicate_job_queued?
log 'already queued', :warn
raise DuplicateJobError, 'already queued'
elsif block_given?
yield
Expand All @@ -31,7 +30,7 @@ def duplicate_job_queued?
def handle_error(error)
log "failed with '#{error.message}'", :warn
case error
when DuplicateJobError then expire
when StandardError then expire
end
end

Expand Down
10 changes: 9 additions & 1 deletion app/jobs/test_bulk_mail_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ def run

super do
self.class.recipients.find_each do |recipient|
recipient.send_devise_notification(:bulk_test)
recipient.test_email

# TODO: user record log of mail activity?
# recipient.update!(notify_log:)
# where("notify_callback -> 'template_id' ?", template_id)
end
end

private

# @return [String]
def template_id
NotifyMailer::TEMPLATE_IDS[:bulk_test]
end
end
end
10 changes: 4 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ def test_user?
email_delivered.where('notify_callback @> ?', { template_id: template_id }.to_json)
}

# scope :new_module_delivered, -> {
# # where("properties -> 'training_module_id' ?| array[:values]", values: mod_names)
# where("notify_callback -> 'template_id' ?", NotifyMailer::TEMPLATE_IDS[:new_module])
# # '2352b6ce-a098-47f0-870a-286308b9798f'
# }

# data
scope :dashboard, -> { not_closed }
scope :month_old_confirmation, -> { where(confirmed_at: 4.weeks.ago.beginning_of_day..4.weeks.ago.end_of_day) }
Expand Down Expand Up @@ -233,6 +227,10 @@ def active_modules
end
end

def test_email
send_devise_notification(:bulk_test) unless Rails.application.live?
end

def send_account_closed_notification
send_devise_notification(:account_closed)
end
Expand Down

0 comments on commit d3a3d5c

Please sign in to comment.