FEATURE: Add Mechanism to redeliver all failed webhook events WIP

This commit is contained in:
Guhyoun Nam 2024-06-13 11:03:47 -05:00
parent e5dac3b422
commit 500e26d1fe
No known key found for this signature in database
GPG Key ID: 4E5F7A35021FBFA6
5 changed files with 45 additions and 0 deletions

View File

@ -13,6 +13,12 @@
class="delivery-status-filters" class="delivery-status-filters"
/> />
<DButton
@icon="sync"
@label="admin.web_hooks.events.redeliver_failed"
@action={{this.redeliverFailed}}
/>
<DButton <DButton
@icon="paper-plane" @icon="paper-plane"
@label="admin.web_hooks.events.ping" @label="admin.web_hooks.events.ping"

View File

@ -11,10 +11,16 @@ import I18n from "discourse-i18n";
export default class WebhookEvents extends Component { export default class WebhookEvents extends Component {
@service messageBus; @service messageBus;
@service store; @service store;
@service dialog;
@tracked pingEnabled = true; @tracked pingEnabled = true;
@tracked events = []; @tracked events = [];
@tracked incomingEventIds = []; @tracked incomingEventIds = [];
@tracked loading = false;
@tracked showProgress = false;
@tracked processedTopicCount = 0;
@tracked count = 0;
@tracked eventIds = [];
@readOnly("incomingEventIds.length") incomingCount; @readOnly("incomingEventIds.length") incomingCount;
@gt("incomingCount", 0) hasIncoming; @gt("incomingCount", 0) hasIncoming;
@ -117,4 +123,27 @@ export default class WebhookEvents extends Component {
popupAjaxError(error); popupAjaxError(error);
} }
} }
@action
redeliverFailed() {
this.eventIds = this.events.content.map((event) => event.id);
this.count = this.events.length;
return this.dialog.yesNoConfirm({
message: I18n.t("admin.web_hooks.events.bulk_redeliver_confirm", {
count: this.count,
}),
didConfirm: async () => {
try {
const json = await ajax(
`/admin/api/web_hooks/${this.args.webhookId}/events/bulk_redeliver`,
{ type: "POST", data: { event_ids: this.eventIds } }
);
this.args.event.setProperties(json.web_hook_event);
} catch (e) {
popupAjaxError(e);
}
},
});
}
} }

View File

@ -135,6 +135,13 @@ class Admin::WebHooksController < Admin::AdminController
end end
end end
def bulk_redeliver_events
limit = 50
offset = params[:offset].to_i
failed_events = @web_hook.web_hook_events.failed.limit(limit).offset(offset)
render_serialized(failed_events, AdminWebHookEventSerializer, root: "web_hook_event")
end
def ping def ping
Jobs.enqueue( Jobs.enqueue(
:emit_web_hook_event, :emit_web_hook_event,

View File

@ -5347,6 +5347,7 @@ en:
request: "Request" request: "Request"
response: "Response" response: "Response"
redeliver_confirm: "Are you sure you want to redeliver the same payload?" redeliver_confirm: "Are you sure you want to redeliver the same payload?"
bulk_redeliver_confirm: "Are you sure you want to redeliver %{count} webhook events? (You can redeliver up to 50 failed events at once.)"
headers: "Headers" headers: "Headers"
payload: "Payload" payload: "Payload"
body: "Body" body: "Body"
@ -5356,6 +5357,7 @@ en:
timestamp: "Created" timestamp: "Created"
completion: "Completion Time" completion: "Completion Time"
actions: "Actions" actions: "Actions"
redeliver_failed: "Redeliver Failed"
filter_status: filter_status:
all: "All Events" all: "All Events"
successful: "Delivered" successful: "Delivered"

View File

@ -344,6 +344,7 @@ Discourse::Application.routes.draw do
get "web_hook_events/:id" => "web_hooks#list_events", :as => :web_hook_events get "web_hook_events/:id" => "web_hooks#list_events", :as => :web_hook_events
get "web_hooks/:id/events/bulk" => "web_hooks#bulk_events" get "web_hooks/:id/events/bulk" => "web_hooks#bulk_events"
post "web_hooks/:web_hook_id/events/:event_id/redeliver" => "web_hooks#redeliver_event" post "web_hooks/:web_hook_id/events/:event_id/redeliver" => "web_hooks#redeliver_event"
post "web_hooks/:web_hook_id/events/bulk_redeliver" => "web_hooks#bulk_redeliver_events"
post "web_hooks/:id/ping" => "web_hooks#ping" post "web_hooks/:id/ping" => "web_hooks#ping"
end end
end end