From cd1a1ab1aa029913d3051c5195b232f244a11423 Mon Sep 17 00:00:00 2001 From: lvillen Date: Fri, 13 Dec 2024 13:21:19 +0100 Subject: [PATCH 1/3] Delete proxy_affecting_change_history.touch job --- .../proxy_config_affecting_change_worker.rb | 21 ----------------- ...oxy_config_affecting_change_worker_test.rb | 23 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 app/workers/proxy_config_affecting_change_worker.rb delete mode 100644 test/workers/proxy_config_affecting_change_worker_test.rb diff --git a/app/workers/proxy_config_affecting_change_worker.rb b/app/workers/proxy_config_affecting_change_worker.rb deleted file mode 100644 index c21d28d981..0000000000 --- a/app/workers/proxy_config_affecting_change_worker.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class ProxyConfigAffectingChangeWorker < ApplicationJob - def perform(event_id) - event = EventStore::Repository.find_event!(event_id) - proxy = Proxy.find(event.proxy_id) - proxy.affecting_change_history.touch - rescue ActiveRecord::StatementInvalid => exception - # logging to help us understand the problem - proxy_config_affecting_change = proxy.reload.send(:proxy_config_affecting_change) - parameters = { - proxy_created_at: proxy.created_at, - proxy_updated_at: proxy.updated_at, - proxy_affecting_change_created_at: proxy_config_affecting_change&.created_at, - proxy_affecting_change_updated_at: proxy_config_affecting_change&.updated_at - } - System::ErrorReporting.report_error(exception, parameters: parameters) - raise - rescue ActiveRecord::RecordNotFound - end -end diff --git a/test/workers/proxy_config_affecting_change_worker_test.rb b/test/workers/proxy_config_affecting_change_worker_test.rb deleted file mode 100644 index 10f0371c81..0000000000 --- a/test/workers/proxy_config_affecting_change_worker_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class ProxyConfigAffectingChangeWorkerTest < ActiveSupport::TestCase - setup do - @worker = ProxyConfigAffectingChangeWorker.new - EventStore::Repository.stubs(raise_errors: true) - end - - attr_reader :worker - - test '#perform' do - proxy = FactoryBot.create(:proxy) - event = ProxyConfigs::AffectingObjectChangedEvent.create_and_publish!(proxy, mock(id: 123)) - - affecting_change_history = mock - Proxy.any_instance.expects(:affecting_change_history).returns(affecting_change_history) - affecting_change_history.expects(:touch) - - worker.perform(event.event_id) - end -end From 0e21e63e23f8530df4a59422db4a51a58ea5e975 Mon Sep 17 00:00:00 2001 From: lvillen Date: Fri, 13 Dec 2024 13:21:47 +0100 Subject: [PATCH 2/3] Add proxy_affecting_change_history.touch to ProxyConfigEventSubscriber --- app/subscribers/proxy_config_event_subscriber.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/subscribers/proxy_config_event_subscriber.rb b/app/subscribers/proxy_config_event_subscriber.rb index ed313dcdce..3bf86e69fb 100644 --- a/app/subscribers/proxy_config_event_subscriber.rb +++ b/app/subscribers/proxy_config_event_subscriber.rb @@ -3,8 +3,11 @@ class ProxyConfigEventSubscriber def call(event) case event - when ProxyConfigs::AffectingObjectChangedEvent then ProxyConfigAffectingChangeWorker.perform_later(event.event_id) - else raise "Unknown event type #{event.class}" + when ProxyConfigs::AffectingObjectChangedEvent + proxy = Proxy.find(event.proxy_id) + proxy.affecting_change_history.touch + else + raise "Unknown event type #{event.class}" end end end From 19dc2f439e0d48df5eeb5c1dfd1c75102a52ba81 Mon Sep 17 00:00:00 2001 From: lvillen Date: Wed, 18 Dec 2024 17:25:22 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=AA=20Update=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/subscribers/proxy_config_event_subscriber_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/subscribers/proxy_config_event_subscriber_test.rb b/test/subscribers/proxy_config_event_subscriber_test.rb index 7754a3ab9a..ba860de947 100644 --- a/test/subscribers/proxy_config_event_subscriber_test.rb +++ b/test/subscribers/proxy_config_event_subscriber_test.rb @@ -8,7 +8,9 @@ class ProxyConfigEventSubscriberTest < ActiveSupport::TestCase proxy_rule = FactoryBot.build_stubbed(:proxy_rule, proxy: proxy) event = ProxyConfigs::AffectingObjectChangedEvent.create(proxy, proxy_rule) - ProxyConfigAffectingChangeWorker.expects(:perform_later).with(event.event_id) + Proxy.stubs(:find).with(event.proxy_id).returns(proxy) + + proxy.affecting_change_history.expects(:touch) ProxyConfigEventSubscriber.new.call(event) end