Code style fixes [SCI-5800]

This commit is contained in:
Martin Artnik 2021-06-17 22:00:13 +02:00
parent 47071e23a1
commit c6648111f3
5 changed files with 15 additions and 13 deletions

View file

@ -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

View file

@ -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

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class RenameWebhookMethodColumn < ActiveRecord::Migration[6.1]
def change
rename_column :webhooks, :method, :http_method

View file

@ -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

View file

@ -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