FEATURE: Add Mechanism to redeliver all failed webhook events WIP
This commit is contained in:
parent
e5dac3b422
commit
500e26d1fe
|
@ -13,6 +13,12 @@
|
|||
class="delivery-status-filters"
|
||||
/>
|
||||
|
||||
<DButton
|
||||
@icon="sync"
|
||||
@label="admin.web_hooks.events.redeliver_failed"
|
||||
@action={{this.redeliverFailed}}
|
||||
/>
|
||||
|
||||
<DButton
|
||||
@icon="paper-plane"
|
||||
@label="admin.web_hooks.events.ping"
|
||||
|
|
|
@ -11,10 +11,16 @@ import I18n from "discourse-i18n";
|
|||
export default class WebhookEvents extends Component {
|
||||
@service messageBus;
|
||||
@service store;
|
||||
@service dialog;
|
||||
|
||||
@tracked pingEnabled = true;
|
||||
@tracked events = [];
|
||||
@tracked incomingEventIds = [];
|
||||
@tracked loading = false;
|
||||
@tracked showProgress = false;
|
||||
@tracked processedTopicCount = 0;
|
||||
@tracked count = 0;
|
||||
@tracked eventIds = [];
|
||||
|
||||
@readOnly("incomingEventIds.length") incomingCount;
|
||||
@gt("incomingCount", 0) hasIncoming;
|
||||
|
@ -117,4 +123,27 @@ export default class WebhookEvents extends Component {
|
|||
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);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,13 @@ class Admin::WebHooksController < Admin::AdminController
|
|||
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
|
||||
Jobs.enqueue(
|
||||
:emit_web_hook_event,
|
||||
|
|
|
@ -5347,6 +5347,7 @@ en:
|
|||
request: "Request"
|
||||
response: "Response"
|
||||
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"
|
||||
payload: "Payload"
|
||||
body: "Body"
|
||||
|
@ -5356,6 +5357,7 @@ en:
|
|||
timestamp: "Created"
|
||||
completion: "Completion Time"
|
||||
actions: "Actions"
|
||||
redeliver_failed: "Redeliver Failed"
|
||||
filter_status:
|
||||
all: "All Events"
|
||||
successful: "Delivered"
|
||||
|
|
|
@ -344,6 +344,7 @@ Discourse::Application.routes.draw do
|
|||
get "web_hook_events/:id" => "web_hooks#list_events", :as => :web_hook_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/bulk_redeliver" => "web_hooks#bulk_redeliver_events"
|
||||
post "web_hooks/:id/ping" => "web_hooks#ping"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue