DEV: Don't destroy webhook in case of error

DEV: Don’t destroy webhook in case of error

diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb
index 643d496..9ab18f8 100644
--- a/app/jobs/regular/emit_web_hook_event.rb
+++ b/app/jobs/regular/emit_web_hook_event.rb
@@ -113,15 +113,15 @@ module Jobs
           response_body: response.body,
           duration: ((Time.zone.now - now) * 1000).to_i
         )
-
-        MessageBus.publish("/web_hook_events/#{web_hook.id}", {
-          web_hook_event_id: web_hook_event.id,
-          event_type: args[:event_type]
-        }, user_ids: User.human_users.staff.pluck(:id))
-      rescue
-        web_hook_event.destroy!
+      rescue => e
+        Rails.logger.error("Webhook event failed: #{e}")
       end
 
+      MessageBus.publish("/web_hook_events/#{web_hook.id}", {
+        web_hook_event_id: web_hook_event.id,
+        event_type: args[:event_type]
+      }, user_ids: User.human_users.staff.pluck(:id))
+
       retry_web_hook if response&.status != 200
     end

GitHub sha: 4c6bfb9b

I think this is worth a test.

1 Like

It’s added in SPEC: Add test case in emit_web_hook_event_spec for commit 4c6bfb9 · discourse/discourse@904ba26 · GitHub

2 Likes