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