diff --git a/app/lib/actions/middleware/keep_current_request_id.rb b/app/lib/actions/middleware/keep_current_request_id.rb index bb412d2d0..73efd6afb 100644 --- a/app/lib/actions/middleware/keep_current_request_id.rb +++ b/app/lib/actions/middleware/keep_current_request_id.rb @@ -1,6 +1,6 @@ module Actions module Middleware - class KeepCurrentRequestID < Dynflow::Middleware + class KeepCurrentRequestId < Dynflow::Middleware def delay(*args) pass(*args).tap { store_current_request_id } end diff --git a/lib/foreman_tasks/engine.rb b/lib/foreman_tasks/engine.rb index f5bcc7585..ca70bf01e 100644 --- a/lib/foreman_tasks/engine.rb +++ b/lib/foreman_tasks/engine.rb @@ -125,7 +125,6 @@ class Engine < ::Rails::Engine register_gettext domain: "foreman_tasks" ForemanTasks.dynflow.eager_load_actions! - extend_observable_events(::Dynflow::Action.descendants.select { |klass| klass <= ::Actions::ObservableAction }.map(&:namespaced_event_names)) end end @@ -160,7 +159,7 @@ class Engine < ::Rails::Engine world.middleware.use Actions::Middleware::KeepCurrentTaxonomies world.middleware.use Actions::Middleware::KeepCurrentUser, :before => ::Dynflow::Middleware::Common::Transaction world.middleware.use Actions::Middleware::KeepCurrentTimezone - world.middleware.use Actions::Middleware::KeepCurrentRequestID + world.middleware.use Actions::Middleware::KeepCurrentRequestId world.middleware.use ::Actions::Middleware::LoadSettingValues ForemanTasks.register_scheduled_task(Actions::CheckLongRunningTasks, ENV['FOREMAN_TASKS_CHECK_LONG_RUNNING_TASKS_CRONLINE'] || '0 0 * * *') end @@ -186,6 +185,16 @@ class Engine < ::Rails::Engine ::Dynflow::ActiveJob::QueueAdapters::JobWrapper.include Actions::TaskSynchronization end + initializer "foreman_tasks.observable_events" do + ActiveSupport.on_load(:"foreman-tasks") do + # Postpone registration of observable events since Actions::ObservableAction is autoloadable constant + # This should be done in to_prepare to be able to use reloading, + # but extend_observable_events is Foreman::Plugin object method, thus using on_load hook + # Which makes registered events not reloadable (they weren't before anyway) + extend_observable_events(::Dynflow::Action.descendants.select { |klass| klass <= ::Actions::ObservableAction }.map(&:namespaced_event_names)) + end + end + rake_tasks do %w[dynflow.rake test.rake export_tasks.rake cleanup.rake generate_task_actions.rake reschedule_long_running_tasks_checker.rake].each do |rake_file| full_path = File.expand_path("../tasks/#{rake_file}", __FILE__) diff --git a/test/lib/actions/middleware/keep_current_request_id_test.rb b/test/lib/actions/middleware/keep_current_request_id_test.rb index e7c3f9f8f..d702eaade 100644 --- a/test/lib/actions/middleware/keep_current_request_id_test.rb +++ b/test/lib/actions/middleware/keep_current_request_id_test.rb @@ -1,9 +1,9 @@ require 'foreman_tasks_test_helper' module ForemanTasks - class KeepCurrentRequestIDTest < ActiveSupport::TestCase + class KeepCurrentRequestIdTest < ActiveSupport::TestCase class DummyAction < Actions::EntryAction - middleware.use ::Actions::Middleware::KeepCurrentRequestID + middleware.use ::Actions::Middleware::KeepCurrentRequestId def plan(plan = false) plan_self if plan @@ -18,7 +18,7 @@ def finalize end end - describe Actions::Middleware::KeepCurrentRequestID do + describe Actions::Middleware::KeepCurrentRequestId do include ::Dynflow::Testing before { @old_id = ::Logging.mdc['request'] }