diff --git a/.rubocop.yml b/.rubocop.yml index 24abb2ef4..e709baf9c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,7 @@ AllCops: - 'node_modules/**/*' - 'locale/*' - 'vendor/**/*' - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 Lint/ShadowingOuterLocalVariable: Enabled: false diff --git a/app/lib/actions/bulk_action.rb b/app/lib/actions/bulk_action.rb index 69d410cbb..0f84338de 100644 --- a/app/lib/actions/bulk_action.rb +++ b/app/lib/actions/bulk_action.rb @@ -9,7 +9,8 @@ class BulkAction < Actions::ActionWithSubPlans # Arguments that all the targets share def plan(action_class, targets, *args, concurrency_limit: nil, **kwargs) check_targets!(targets) - limit_concurrency_level!(concurrency_limit) if concurrency_limit + extracted_concurrency_limit = extract_concurrency_limit(args, concurrency_limit) + limit_concurrency_level!(extracted_concurrency_limit) if extracted_concurrency_limit plan_self(:action_class => action_class.to_s, :target_ids => targets.map(&:id), :target_class => targets.first.class.to_s, @@ -72,5 +73,11 @@ def batch(from, size) def total_count input[:target_ids].count end + + private + + def extract_concurrency_limit(args = [], limit = nil) + args.find { |arg| arg.is_a?(Hash) && arg.key?(:concurrency_limit) }&.fetch(:concurrency_limit, limit) + end end end diff --git a/app/models/foreman_tasks/concerns/action_triggering.rb b/app/models/foreman_tasks/concerns/action_triggering.rb index 53352b8f9..262cfe473 100644 --- a/app/models/foreman_tasks/concerns/action_triggering.rb +++ b/app/models/foreman_tasks/concerns/action_triggering.rb @@ -23,12 +23,12 @@ def update_action; end # @override def destroy_action; end - def save(*args) - dynflow_task_wrap(:save) { super(*args) } + def save(...) + dynflow_task_wrap(:save) { super(...) } end - def save!(*args) - dynflow_task_wrap(:save) { super(*args) } + def save!(...) + dynflow_task_wrap(:save) { super(...) } end def destroy @@ -37,14 +37,14 @@ def destroy # In order to use host._changed?, we must assign_attributes to # the host record for these update and update! methods. - def update(*args) - assign_attributes(*args) + def update(...) + assign_attributes(...) dynflow_task_wrap(:save) { save } end alias update_attributes update - def update!(*args) - assign_attributes(*args) + def update!(...) + assign_attributes(...) dynflow_task_wrap(:save) { save! } end alias update_attributes! update!