From 64b73a348a316646d3445a65ece9920c9b76d508 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 8 Jan 2015 18:56:54 -0300 Subject: [PATCH] Avoid loop in person notification job --- app/models/person_notifier.rb | 8 ++++++-- test/unit/person_notifier_test.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb index 8f6be19..e6ec250 100644 --- a/app/models/person_notifier.rb +++ b/app/models/person_notifier.rb @@ -59,8 +59,12 @@ class PersonNotifier end def failure(job) - person = Person.find(person_id) - person.notifier.dispatch_notification_mail + begin + person = Person.find(person_id) + person.notifier.dispatch_notification_mail + rescue + Rails.logger.error "PersonNotifier::NotifyJob: Cannot recover from failure" + end end end diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb index c862cd3..d0f8743 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -234,6 +234,18 @@ class PersonNotifierTest < ActiveSupport::TestCase assert_match /src="http:\/\/.*\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s end + should 'do not raise errors in NotifyJob failure to avoid loop' do + Delayed::Worker.max_attempts = 1 + Delayed::Job.enqueue(PersonNotifier::NotifyJob.new(@member.id)) + + PersonNotifier.any_instance.stubs(:notify).raises('error') + PersonNotifier.any_instance.stubs(:dispatch_notification_mail).raises('error') + + process_delayed_job_queue + jobs = PersonNotifier::NotifyJob.find(@member.id) + assert jobs.select {|j| !j.failed? && j.last_error.nil? }.empty? + end + private def notify -- libgit2 0.21.2