diff --git a/app/models/activity.rb b/app/models/activity.rb index ddb72dc69..2bc3394b1 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -63,7 +63,7 @@ class Activity < ApplicationRecord breadcrumbs: {} ) - after_create :dispatch_webhooks + after_create ->(activity) { Activities::DispatchWebhooksJob.perform_later(activity) } def self.activity_types_list activity_list = type_ofs.map do |key, value| @@ -153,8 +153,4 @@ class Activity < ApplicationRecord def activity_version errors.add(:activity, 'wrong combination of associations') if (experiment_id || my_module_id) && subject end - - def dispatch_webhooks - Activities::DispatchWebhooksJob.perform_later(self) - end end diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb index e540bfd4d..ab3e809c3 100644 --- a/app/services/webhook_service.rb +++ b/app/services/webhook_service.rb @@ -42,7 +42,7 @@ class WebhookService def log_error!(message) error_count = @webhook.error_count + 1 - @webhook.update( + @webhook.update!( error_count: error_count, last_error: message ) @@ -51,6 +51,6 @@ class WebhookService def disable_webhook_if_broken! return if @webhook.error_count < DISABLE_WEBHOOK_ERROR_THRESHOLD - @webhook.update(active: false) + @webhook.update!(active: false) end end diff --git a/db/migrate/20210616071836_add_error_info_to_webhooks.rb b/db/migrate/20210616071836_add_error_info_to_webhooks.rb deleted file mode 100644 index 2b19e31d0..000000000 --- a/db/migrate/20210616071836_add_error_info_to_webhooks.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class AddErrorInfoToWebhooks < ActiveRecord::Migration[6.1] - def change - add_column :webhooks, :error_count, :integer, default: 0, null: false - add_column :webhooks, :last_error, :text - end -end diff --git a/db/migrate/20210616071836_add_error_info_to_webhooks_and_rename_method_column.rb b/db/migrate/20210616071836_add_error_info_to_webhooks_and_rename_method_column.rb new file mode 100644 index 000000000..67e6ff4cc --- /dev/null +++ b/db/migrate/20210616071836_add_error_info_to_webhooks_and_rename_method_column.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddErrorInfoToWebhooksAndRenameMethodColumn < ActiveRecord::Migration[6.1] + def change + change_table :webhooks, bulk: true do |t| + t.integer :error_count, default: 0, null: false + t.text :last_error, :text + t.rename :method, :http_method + end + end +end diff --git a/db/migrate/20210617111749_rename_webhook_method_column.rb b/db/migrate/20210617111749_rename_webhook_method_column.rb deleted file mode 100644 index 1d56e9ea4..000000000 --- a/db/migrate/20210617111749_rename_webhook_method_column.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class RenameWebhookMethodColumn < ActiveRecord::Migration[6.1] - def change - rename_column :webhooks, :method, :http_method - end -end diff --git a/db/structure.sql b/db/structure.sql index 7bd13e5ec..53ce84c91 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2803,7 +2803,8 @@ CREATE TABLE public.webhooks ( created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, error_count integer DEFAULT 0 NOT NULL, - last_error text + last_error text, + text text ); @@ -7351,7 +7352,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210506125657'), ('20210531114633'), ('20210603152345'), -('20210616071836'), -('20210617111749'); +('20210616071836');