mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 14:24:27 +08:00
784c04ea81
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.
50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WebHookEvent < ActiveRecord::Base
|
|
scope :successful, -> { where("status >= 200 AND status <= 299") }
|
|
scope :failed, -> { where("status < 200 OR status > 299") }
|
|
scope :not_ping, -> { where("status <> 0") }
|
|
belongs_to :web_hook
|
|
|
|
has_one :redelivering_webhook_event, class_name: "RedeliveringWebhookEvent"
|
|
|
|
after_save :update_web_hook_delivery_status
|
|
|
|
default_scope { order("created_at DESC") }
|
|
|
|
def self.purge_old
|
|
where("created_at < ?", SiteSetting.retain_web_hook_events_period_days.days.ago).delete_all
|
|
end
|
|
|
|
def update_web_hook_delivery_status
|
|
web_hook.last_delivery_status =
|
|
case status
|
|
when 200..299
|
|
WebHook.last_delivery_statuses[:successful]
|
|
else
|
|
WebHook.last_delivery_statuses[:failed]
|
|
end
|
|
web_hook.save!
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: web_hook_events
|
|
#
|
|
# id :integer not null, primary key
|
|
# web_hook_id :integer not null
|
|
# headers :string
|
|
# payload :text
|
|
# status :integer default(0)
|
|
# response_headers :string
|
|
# response_body :text
|
|
# duration :integer default(0)
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_web_hook_events_on_web_hook_id (web_hook_id)
|
|
#
|