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 Aug 30, 2024
1 parent b07ebc5 commit 35fa271
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 106 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
206 changes: 104 additions & 102 deletions lib/foreman_tasks/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,116 +16,118 @@ class Engine < ::Rails::Engine
SETTINGS[:foreman_tasks] = { :assets => { :precompile => assets_to_precompile } }
end

initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |_app|
Foreman::Plugin.register :"foreman-tasks" do
requires_foreman '>= 3.9'
divider :top_menu, :parent => :monitor_menu, :last => true, :caption => N_('Foreman Tasks')
menu :top_menu, :tasks,
:url_hash => { :controller => 'foreman_tasks/tasks', :action => :index },
:caption => N_('Tasks'),
:parent => :monitor_menu,
:last => true

menu :top_menu, :recurring_logics,
:url_hash => { :controller => 'foreman_tasks/recurring_logics', :action => :index },
:caption => N_('Recurring Logics'),
:parent => :monitor_menu,
:last => true

security_block :foreman_tasks do |_map|
permission :view_foreman_tasks, { :'foreman_tasks/tasks' => [:auto_complete_search, :sub_tasks, :index, :summary, :summary_sub_tasks, :show],
:'foreman_tasks/react' => [:index],
:'foreman_tasks/api/tasks' => [:bulk_search, :show, :index, :summary, :summary_sub_tasks, :details, :sub_tasks] }, :resource_type => 'ForemanTasks::Task'
permission :edit_foreman_tasks, { :'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel, :abort],
:'foreman_tasks/api/tasks' => [:bulk_resume, :bulk_cancel, :bulk_stop] }, :resource_type => 'ForemanTasks::Task'

permission :create_recurring_logics, {}, :resource_type => 'ForemanTasks::RecurringLogic'

permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:auto_complete_search, :index, :show],
:'foreman_tasks/api/recurring_logics' => [:index, :show] }, :resource_type => 'ForemanTasks::RecurringLogic'

permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel, :enable, :disable, :clear_cancelled],
:'foreman_tasks/api/recurring_logics' => [:cancel, :update, :bulk_destroy] }, :resource_type => 'ForemanTasks::RecurringLogic'
end
initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |app|
app.reloader.to_prepare do
Foreman::Plugin.register :"foreman-tasks" do
requires_foreman '>= 3.12'
divider :top_menu, :parent => :monitor_menu, :last => true, :caption => N_('Foreman Tasks')
menu :top_menu, :tasks,
:url_hash => { :controller => 'foreman_tasks/tasks', :action => :index },
:caption => N_('Tasks'),
:parent => :monitor_menu,
:last => true

menu :top_menu, :recurring_logics,
:url_hash => { :controller => 'foreman_tasks/recurring_logics', :action => :index },
:caption => N_('Recurring Logics'),
:parent => :monitor_menu,
:last => true

security_block :foreman_tasks do |_map|
permission :view_foreman_tasks, { :'foreman_tasks/tasks' => [:auto_complete_search, :sub_tasks, :index, :summary, :summary_sub_tasks, :show],
:'foreman_tasks/react' => [:index],
:'foreman_tasks/api/tasks' => [:bulk_search, :show, :index, :summary, :summary_sub_tasks, :details, :sub_tasks] }, :resource_type => 'ForemanTasks::Task'
permission :edit_foreman_tasks, { :'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel, :abort],
:'foreman_tasks/api/tasks' => [:bulk_resume, :bulk_cancel, :bulk_stop] }, :resource_type => 'ForemanTasks::Task'

permission :create_recurring_logics, {}, :resource_type => 'ForemanTasks::RecurringLogic'

permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:auto_complete_search, :index, :show],
:'foreman_tasks/api/recurring_logics' => [:index, :show] }, :resource_type => 'ForemanTasks::RecurringLogic'

permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel, :enable, :disable, :clear_cancelled],
:'foreman_tasks/api/recurring_logics' => [:cancel, :update, :bulk_destroy] }, :resource_type => 'ForemanTasks::RecurringLogic'
end

add_all_permissions_to_default_roles

settings do
category(:tasks, N_('Tasks')) do
setting('foreman_tasks_sync_task_timeout',
type: :integer,
description: N_('Number of seconds to wait for synchronous task to finish.'),
default: 120,
full_name: N_('Sync task timeout'))
setting('dynflow_enable_console',
type: :boolean,
description: N_('Enable the dynflow console (/foreman_tasks/dynflow) for debugging'),
default: true,
full_name: N_('Enable dynflow console'))
setting('dynflow_console_require_auth',
type: :boolean,
description: N_('Require user to be authenticated as user with admin rights when accessing dynflow console'),
default: true,
full_name: N_('Require auth for dynflow console'))
setting('foreman_tasks_proxy_action_retry_count',
type: :integer,
description: N_('Number of attempts to start a task on the smart proxy before failing'),
default: 4,
full_name: N_('Proxy action retry count'))
setting('foreman_tasks_proxy_action_retry_interval',
type: :integer,
description: N_('Time in seconds between retries'),
default: 15,
full_name: N_('Proxy action retry interval'))
setting('foreman_tasks_proxy_batch_trigger',
type: :boolean,
description: N_('Allow triggering tasks on the smart proxy in batches'),
default: true,
full_name: N_('Allow proxy batch tasks'))
setting('foreman_tasks_proxy_batch_size',
type: :integer,
description: N_('Number of tasks which should be sent to the smart proxy in one request, if foreman_tasks_proxy_batch_trigger is enabled'),
default: 100,
full_name: N_('Proxy tasks batch size'))
setting('foreman_tasks_troubleshooting_url',
type: :string,
description: N_('Url pointing to the task troubleshooting documentation. '\
'It should contain %{label} placeholder, that will be replaced with normalized task label '\
'(restricted to only alphanumeric characters)). %{version} placeholder is also available.'),
default: nil,
full_name: N_('Tasks troubleshooting URL'))
setting('foreman_tasks_polling_multiplier',
type: :integer,
description: N_('Polling multiplier which is used to multiply the default polling intervals. '\
'This can be used to prevent polling too frequently for long running tasks.'),
default: 1,
full_name: N_("Polling intervals multiplier"),
validate: { numericality: { greater_than: 0 } })
add_all_permissions_to_default_roles

settings do
category(:tasks, N_('Tasks')) do
setting('foreman_tasks_sync_task_timeout',
type: :integer,
description: N_('Number of seconds to wait for synchronous task to finish.'),
default: 120,
full_name: N_('Sync task timeout'))
setting('dynflow_enable_console',
type: :boolean,
description: N_('Enable the dynflow console (/foreman_tasks/dynflow) for debugging'),
default: true,
full_name: N_('Enable dynflow console'))
setting('dynflow_console_require_auth',
type: :boolean,
description: N_('Require user to be authenticated as user with admin rights when accessing dynflow console'),
default: true,
full_name: N_('Require auth for dynflow console'))
setting('foreman_tasks_proxy_action_retry_count',
type: :integer,
description: N_('Number of attempts to start a task on the smart proxy before failing'),
default: 4,
full_name: N_('Proxy action retry count'))
setting('foreman_tasks_proxy_action_retry_interval',
type: :integer,
description: N_('Time in seconds between retries'),
default: 15,
full_name: N_('Proxy action retry interval'))
setting('foreman_tasks_proxy_batch_trigger',
type: :boolean,
description: N_('Allow triggering tasks on the smart proxy in batches'),
default: true,
full_name: N_('Allow proxy batch tasks'))
setting('foreman_tasks_proxy_batch_size',
type: :integer,
description: N_('Number of tasks which should be sent to the smart proxy in one request, if foreman_tasks_proxy_batch_trigger is enabled'),
default: 100,
full_name: N_('Proxy tasks batch size'))
setting('foreman_tasks_troubleshooting_url',
type: :string,
description: N_('Url pointing to the task troubleshooting documentation. '\
'It should contain %{label} placeholder, that will be replaced with normalized task label '\
'(restricted to only alphanumeric characters)). %{version} placeholder is also available.'),
default: nil,
full_name: N_('Tasks troubleshooting URL'))
setting('foreman_tasks_polling_multiplier',
type: :integer,
description: N_('Polling multiplier which is used to multiply the default polling intervals. '\
'This can be used to prevent polling too frequently for long running tasks.'),
default: 1,
full_name: N_("Polling intervals multiplier"),
validate: { numericality: { greater_than: 0 } })
end
end
end

register_graphql_query_field :task, '::Types::Task', :record_field
register_graphql_query_field :tasks, '::Types::Task', :collection_field
register_graphql_query_field :recurring_logic, '::Types::RecurringLogic', :record_field
register_graphql_query_field :recurring_logics, '::Types::RecurringLogic', :collection_field
register_graphql_query_field :task, '::Types::Task', :record_field
register_graphql_query_field :tasks, '::Types::Task', :collection_field
register_graphql_query_field :recurring_logic, '::Types::RecurringLogic', :record_field
register_graphql_query_field :recurring_logics, '::Types::RecurringLogic', :collection_field

register_graphql_mutation_field :cancel_recurring_logic, '::Mutations::RecurringLogics::Cancel'
register_graphql_mutation_field :cancel_recurring_logic, '::Mutations::RecurringLogics::Cancel'

logger :dynflow, :enabled => true
logger :action, :enabled => true
logger :dynflow, :enabled => true
logger :action, :enabled => true

role 'Tasks Manager', [:view_foreman_tasks, :edit_foreman_tasks],
'Role granting permissions to inspect, cancel, resume and unlock tasks'
role 'Tasks Reader', [:view_foreman_tasks],
'Role granting permissions to inspect tasks'
role 'Tasks Manager', [:view_foreman_tasks, :edit_foreman_tasks],
'Role granting permissions to inspect, cancel, resume and unlock tasks'
role 'Tasks Reader', [:view_foreman_tasks],
'Role granting permissions to inspect tasks'

widget 'foreman_tasks/tasks/dashboard/tasks_status', :sizex => 6, :sizey => 1, :name => N_('Task Status')
widget 'foreman_tasks/tasks/dashboard/latest_tasks_in_error_warning', :sizex => 6, :sizey => 1, :name => N_('Latest Warning/Error Tasks')
widget 'foreman_tasks/tasks/dashboard/tasks_status', :sizex => 6, :sizey => 1, :name => N_('Task Status')
widget 'foreman_tasks/tasks/dashboard/latest_tasks_in_error_warning', :sizex => 6, :sizey => 1, :name => N_('Latest Warning/Error Tasks')

register_gettext domain: "foreman_tasks"
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))
ForemanTasks.dynflow.eager_load_actions!
extend_observable_events(::Dynflow::Action.descendants.select { |klass| klass <= ::Actions::ObservableAction }.map(&:namespaced_event_names))
end
end
end

Expand Down Expand Up @@ -160,7 +162,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 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 35fa271

Please sign in to comment.