FIX: Rescue errors in job. (#6745)

FIX: Rescue errors in job. (#6745)
diff --git a/plugins/poll/jobs/regular/close_poll.rb b/plugins/poll/jobs/regular/close_poll.rb
index 6e75241..1c3c77c 100644
--- a/plugins/poll/jobs/regular/close_poll.rb
+++ b/plugins/poll/jobs/regular/close_poll.rb
@@ -14,7 +14,8 @@ module Jobs
         args[:post_id],
         args[:poll_name],
         "closed",
-        Discourse.system_user
+        Discourse.system_user,
+        false
       )
     end
 
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 9d62323..b0bc4cd 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -108,28 +108,34 @@ after_initialize do
         end
       end
 
-      def toggle_status(post_id, poll_name, status, user)
+      def toggle_status(post_id, poll_name, status, user, raise_errors = true)
         Poll.transaction do
           post = Post.find_by(id: post_id)
 
           # post must not be deleted
           if post.nil? || post.trashed?
-            raise StandardError.new I18n.t("poll.post_is_deleted")
+            raise StandardError.new I18n.t("poll.post_is_deleted") if raise_errors
+            return
           end
 
           # topic must not be archived
           if post.topic&.archived
-            raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status")
+            raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status") if raise_errors
+            return
           end
 
           # either staff member or OP
           unless post.user_id == user&.id || user&.staff?
-            raise StandardError.new I18n.t("poll.only_staff_or_op_can_toggle_status")
+            raise StandardError.new I18n.t("poll.only_staff_or_op_can_toggle_status") if raise_errors
+            return
           end
 
           poll = Poll.find_by(post_id: post_id, name: poll_name)
 
-          raise StandardError.new I18n.t("poll.no_poll_with_this_name", name: poll_name) unless poll
+          if !poll
+            raise StandardError.new I18n.t("poll.no_poll_with_this_name", name: poll_name) if raise_errors
+            return
+          end
 
           poll.status = status
           poll.save!

GitHub
sha: 5bda4d26

I think this needs to be tested at least at the job level :slight_smile: