mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Code style fixes [SCI-5800]
This commit is contained in:
parent
47071e23a1
commit
c6648111f3
|
@ -14,12 +14,12 @@ class WebhookService
|
|||
unless @webhook.active?
|
||||
raise(
|
||||
Activities::WebhooksService::InactiveWebhookSendException.new(
|
||||
"Refused to send inactive webhook."
|
||||
'Refused to send inactive webhook.'
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
response = HTTParty.send(
|
||||
response = HTTParty.public_send(
|
||||
@webhook.http_method,
|
||||
@webhook.url,
|
||||
{
|
||||
|
@ -28,21 +28,18 @@ class WebhookService
|
|||
}
|
||||
)
|
||||
|
||||
unless response.success?
|
||||
log_error!("#{response.code}: #{response.message}")
|
||||
end
|
||||
log_error!("#{response.code}: #{response.message}") unless response.success?
|
||||
|
||||
response
|
||||
rescue Net::ReadTimeout, Net::OpenTimeout, SocketError => error
|
||||
log_error!(error)
|
||||
raise error
|
||||
rescue Net::ReadTimeout, Net::OpenTimeout, SocketError => e
|
||||
log_error!(e)
|
||||
raise e
|
||||
ensure
|
||||
disable_webhook_if_broken!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def log_error!(message)
|
||||
error_count = @webhook.error_count + 1
|
||||
|
||||
|
@ -54,6 +51,7 @@ class WebhookService
|
|||
|
||||
def disable_webhook_if_broken!
|
||||
return if @webhook.error_count < DISABLE_WEBHOOK_ERROR_THRESHOLD
|
||||
|
||||
@webhook.update(active: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddErrorInfoToWebhooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :webhooks, :error_count, :integer, default: 0, null: false
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RenameWebhookMethodColumn < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
rename_column :webhooks, :method, :http_method
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
FactoryBot.define do
|
||||
factory :activity_filter do
|
||||
name { "type filter 1" }
|
||||
filter { {"types" => ["0"], "from_date" => "", "to_date" => ""} }
|
||||
name { 'type filter 1' }
|
||||
filter { { 'types' => %w(0), 'from_date' => '', 'to_date' => '' } }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
FactoryBot.define do
|
||||
factory :webhook do
|
||||
activity_filter
|
||||
http_method { "post" }
|
||||
url { "https://www.example.com" }
|
||||
http_method { 'post' }
|
||||
url { 'https://www.example.com' }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue