FEATURE: Add Mechanism to redeliver all failed webhook events (#27609)

Background:
In order to redrive failed webhook events, an operator has to go through and click on each. This PR is adding a mechanism to retry all failed events to help resolve issues quickly once the underlying failure has been resolved.

What is the change?:
Previously, we had to redeliver each webhook event. This merge is adding a 'Redeliver Failed' button next to the webhook event filter to redeliver all failed events. If there is no failed webhook events to redeliver, 'Redeliver Failed' gets disabled. If you click it, a window pops up to confirm the operator. Failed webhook events will be added to the queue and webhook event list will show the redelivering progress. Every minute, a job will be ran to go through 20 events to redeliver. Every hour, a job will cleanup the redelivering events which have been stored more than 8 hours.
This commit is contained in:
Guhyoun Nam
2024-07-08 15:43:16 -05:00
committed by GitHub
parent 16a8a31c52
commit 784c04ea81
17 changed files with 305 additions and 4 deletions

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
class Admin::WebHooksController < Admin::AdminController
before_action :fetch_web_hook, only: %i[show update destroy list_events bulk_events ping]
before_action :fetch_web_hook,
only: %i[show update destroy list_events bulk_events ping redeliver_failed_events]
def index
limit = 50
@ -93,7 +94,7 @@ class Admin::WebHooksController < Admin::AdminController
def list_events
limit = 50
offset = params[:offset].to_i
events = @web_hook.web_hook_events
events = @web_hook.web_hook_events.includes(:redelivering_webhook_event)
status = params[:status]
if status == "successful"
events = events.successful
@ -141,6 +142,24 @@ class Admin::WebHooksController < Admin::AdminController
end
end
def redeliver_failed_events
web_hook_events =
@web_hook
.web_hook_events
.includes(:redelivering_webhook_event)
.not_ping
.where(id: params[:event_ids])
raise Discourse::InvalidParameters if web_hook_events.count.zero?
web_hook_events.each do |web_hook_event|
if !web_hook_event.redelivering_webhook_event
RedeliveringWebhookEvent.create!(web_hook_event: web_hook_event)
end
end
render json: { event_ids: web_hook_events.map(&:id) }
end
def ping
Jobs.enqueue(
:emit_web_hook_event,