Commit 64b73a348a316646d3445a65ece9920c9b76d508
1 parent
bd55ad60
Exists in
master
and in
29 other branches
Avoid loop in person notification job
Showing
2 changed files
with
18 additions
and
2 deletions
Show diff stats
app/models/person_notifier.rb
@@ -59,8 +59,12 @@ class PersonNotifier | @@ -59,8 +59,12 @@ class PersonNotifier | ||
59 | end | 59 | end |
60 | 60 | ||
61 | def failure(job) | 61 | def failure(job) |
62 | - person = Person.find(person_id) | ||
63 | - person.notifier.dispatch_notification_mail | 62 | + begin |
63 | + person = Person.find(person_id) | ||
64 | + person.notifier.dispatch_notification_mail | ||
65 | + rescue | ||
66 | + Rails.logger.error "PersonNotifier::NotifyJob: Cannot recover from failure" | ||
67 | + end | ||
64 | end | 68 | end |
65 | 69 | ||
66 | end | 70 | end |
test/unit/person_notifier_test.rb
@@ -234,6 +234,18 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -234,6 +234,18 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
234 | assert_match /src="http:\/\/.*\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s | 234 | assert_match /src="http:\/\/.*\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s |
235 | end | 235 | end |
236 | 236 | ||
237 | + should 'do not raise errors in NotifyJob failure to avoid loop' do | ||
238 | + Delayed::Worker.max_attempts = 1 | ||
239 | + Delayed::Job.enqueue(PersonNotifier::NotifyJob.new(@member.id)) | ||
240 | + | ||
241 | + PersonNotifier.any_instance.stubs(:notify).raises('error') | ||
242 | + PersonNotifier.any_instance.stubs(:dispatch_notification_mail).raises('error') | ||
243 | + | ||
244 | + process_delayed_job_queue | ||
245 | + jobs = PersonNotifier::NotifyJob.find(@member.id) | ||
246 | + assert jobs.select {|j| !j.failed? && j.last_error.nil? }.empty? | ||
247 | + end | ||
248 | + | ||
237 | private | 249 | private |
238 | 250 | ||
239 | def notify | 251 | def notify |