2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-15 12:49:57 -05:00
|
|
|
class WebHookEvent < ActiveRecord::Base
|
|
|
|
belongs_to :web_hook
|
|
|
|
|
|
|
|
after_save :update_web_hook_delivery_status
|
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
default_scope { order("created_at DESC") }
|
2016-06-15 12:49:57 -05:00
|
|
|
|
2017-11-08 00:08:30 -06:00
|
|
|
def self.purge_old
|
2023-01-09 06:20:10 -06:00
|
|
|
where("created_at < ?", SiteSetting.retain_web_hook_events_period_days.days.ago).delete_all
|
2017-11-08 00:08:30 -06:00
|
|
|
end
|
|
|
|
|
2016-06-15 12:49:57 -05:00
|
|
|
def update_web_hook_delivery_status
|
2017-07-27 20:20:09 -05:00
|
|
|
web_hook.last_delivery_status =
|
|
|
|
case status
|
|
|
|
when 200..299
|
|
|
|
WebHook.last_delivery_statuses[:successful]
|
|
|
|
else
|
|
|
|
WebHook.last_delivery_statuses[:failed]
|
|
|
|
end
|
2016-06-15 12:49:57 -05:00
|
|
|
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
|
2016-10-31 04:32:11 -05:00
|
|
|
# status :integer default(0)
|
2016-06-15 12:49:57 -05:00
|
|
|
# response_headers :string
|
|
|
|
# response_body :text
|
|
|
|
# duration :integer default(0)
|
2019-01-11 13:29:56 -06:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2016-06-15 12:49:57 -05:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_web_hook_events_on_web_hook_id (web_hook_id)
|
|
|
|
#
|