Skip to content

Commit

Permalink
Fixes #37452 - Support Zeitwerk loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed May 14, 2024
1 parent 9cf91af commit 9d9360e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/lib/actions/middleware/keep_current_request_id.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 11 additions & 2 deletions lib/foreman_tasks/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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__)
Expand Down
6 changes: 3 additions & 3 deletions test/lib/actions/middleware/keep_current_request_id_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'] }
Expand Down

0 comments on commit 9d9360e

Please sign in to comment.