From a56991aede9d7dc403bc5f13c92c2a10382f6448 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Wed, 13 Sep 2017 10:11:04 -0400 Subject: [PATCH] add exception notifier for failed jobs --- app/services/follow_service.rb | 12 +++++++++--- config/initializers/delayed_job.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 config/initializers/delayed_job.rb diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 484fc8ad..87ac3be5 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true class FollowService - class << self + class << self def follow(entity, user, reason) return unless user @@ -8,7 +8,9 @@ class FollowService return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason) follow = Follow.where(followed: entity, user: user).first_or_create - follow.update(muted: false) + unless follow.update(muted: false) + raise follow.errors.full_messages.join("\n") + end if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) follow.follow_reason.update_attribute(reason, true) end @@ -16,7 +18,11 @@ class FollowService def unfollow(entity, user) follow = Follow.where(followed: entity, user: user).first - follow.update(muted: true) + if follow + unless follow.update(muted: true) + raise follow.errors.full_messages.join("\n") + end + end end def remove_reason(entity, user, reason) diff --git a/config/initializers/delayed_job.rb b/config/initializers/delayed_job.rb new file mode 100644 index 00000000..d3132394 --- /dev/null +++ b/config/initializers/delayed_job.rb @@ -0,0 +1,9 @@ +Delayed::Worker.class_eval do + + def handle_failed_job_with_notification(job, error) + handle_failed_job_without_notification(job, error) + ExceptionNotifier.notify_exception(error) + end + alias_method_chain :handle_failed_job, :notification + +end