From 615428131d6a8df8aac9fc0987d90f3985704257 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Thu, 25 Jan 2024 13:40:28 +0000 Subject: [PATCH] Fix more places for kwargs --- lib/dynflow/action.rb | 6 +++--- lib/dynflow/action/v2/with_sub_plans.rb | 4 ++-- lib/dynflow/action/with_sub_plans.rb | 10 +++++----- lib/dynflow/execution_plan/steps/abstract_flow_step.rb | 4 ++-- lib/dynflow/testing/assertions.rb | 8 ++++---- lib/dynflow/testing/dummy_planned_action.rb | 5 +++-- lib/dynflow/testing/factories.rb | 8 ++++---- lib/dynflow/world.rb | 4 ++-- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/dynflow/action.rb b/lib/dynflow/action.rb index b6f4d48b9..1421e148f 100644 --- a/lib/dynflow/action.rb +++ b/lib/dynflow/action.rb @@ -378,15 +378,15 @@ def save_state(conditions = {}) @step.save(conditions) end - def delay(delay_options, *args) - Serializers::Noop.new(args) + def delay(delay_options, *args, **kwargs) + Serializers::Noop.new(args, nil, kwargs) end # @override to implement the action's *Plan phase* behaviour. # By default it plans itself and expects input-hash. # Use #plan_self and #plan_action methods to plan actions. # It can use DB in this phase. - def plan(*args) + def plan(*args) # TODO if from_subscription? # if the action is triggered by subscription, by default use the # input of parent action. diff --git a/lib/dynflow/action/v2/with_sub_plans.rb b/lib/dynflow/action/v2/with_sub_plans.rb index de5537778..7220733c9 100644 --- a/lib/dynflow/action/v2/with_sub_plans.rb +++ b/lib/dynflow/action/v2/with_sub_plans.rb @@ -146,8 +146,8 @@ def check_for_errors! end # Helper for creating sub plans - def trigger(action_class, *args) - world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) } + def trigger(action_class, *args, **kwargs) + world.trigger { world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self) } end # Concurrency limitting diff --git a/lib/dynflow/action/with_sub_plans.rb b/lib/dynflow/action/with_sub_plans.rb index 259a32743..2ef47c16e 100644 --- a/lib/dynflow/action/with_sub_plans.rb +++ b/lib/dynflow/action/with_sub_plans.rb @@ -83,16 +83,16 @@ def abort! end # Helper for creating sub plans - def trigger(action_class, *args) + def trigger(action_class, *args, **kwargs) if uses_concurrency_control - trigger_with_concurrency_control(action_class, *args) + trigger_with_concurrency_control(action_class, *args, **kwargs) else - world.trigger { world.plan_with_options(action_class: action_class, args: args, caller_action: self) } + world.trigger { world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self) } end end - def trigger_with_concurrency_control(action_class, *args) - record = world.plan_with_options(action_class: action_class, args: args, caller_action: self) + def trigger_with_concurrency_control(action_class, *args, **kwargs) + record = world.plan_with_options(action_class: action_class, args: args, kwargs: kwargs, caller_action: self) records = [[record.id], []] records.reverse! unless record.state == :planned @world.throttle_limiter.handle_plans!(execution_plan_id, *records).first diff --git a/lib/dynflow/execution_plan/steps/abstract_flow_step.rb b/lib/dynflow/execution_plan/steps/abstract_flow_step.rb index f9c471b23..178134402 100644 --- a/lib/dynflow/execution_plan/steps/abstract_flow_step.rb +++ b/lib/dynflow/execution_plan/steps/abstract_flow_step.rb @@ -11,11 +11,11 @@ def update_from_action(action) @queue ||= :default end - def execute(*args) + def execute(*args, **kwargs) return self if [:skipped, :success].include? self.state open_action do |action| with_meta_calculation(action) do - action.execute(*args) + action.execute(*args, **kwargs) @delayed_events = action.delayed_events end end diff --git a/lib/dynflow/testing/assertions.rb b/lib/dynflow/testing/assertions.rb index a3faecacc..d28f0f8ce 100644 --- a/lib/dynflow/testing/assertions.rb +++ b/lib/dynflow/testing/assertions.rb @@ -4,13 +4,13 @@ module Testing module Assertions # assert that +assert_actioned_plan+ was planned by +action+ with arguments +plan_input+ # alternatively plan-input can be asserted with +block+ - def assert_action_planned_with(action, planned_action_class, *plan_input, &block) + def assert_action_planned_with(action, planned_action_class, *plan_input, **plan_input_kwargs, &block) found_classes = assert_action_planned(action, planned_action_class) found = found_classes.select do |a| - if plan_input.empty? - block.call a.plan_input + if plan_input.empty? && plan_input_kwargs.empty? + block.call(*a.plan_input, **a.plan_input_kwargs) else - a.plan_input == plan_input + a.plan_input == plan_input && a.plan_input_kwargs == plan_input_kwargs end end diff --git a/lib/dynflow/testing/dummy_planned_action.rb b/lib/dynflow/testing/dummy_planned_action.rb index c9b552a67..f34f2b44b 100644 --- a/lib/dynflow/testing/dummy_planned_action.rb +++ b/lib/dynflow/testing/dummy_planned_action.rb @@ -2,7 +2,7 @@ module Dynflow module Testing class DummyPlannedAction - attr_accessor :output, :plan_input + attr_accessor :output, :plan_input, :plan_input_kwargs include Mimic def initialize(klass) @@ -11,8 +11,9 @@ def initialize(klass) Testing.get_id.to_s, Testing.get_id, Testing.get_id) end - def execute(execution_plan, event, from_subscription, *args) + def execute(execution_plan, event, from_subscription, *args, **kwargs) @plan_input = args + @plan_input_kwargs = kwargs self end diff --git a/lib/dynflow/testing/factories.rb b/lib/dynflow/testing/factories.rb index 855d8f6c7..d93bfbbfb 100644 --- a/lib/dynflow/testing/factories.rb +++ b/lib/dynflow/testing/factories.rb @@ -36,16 +36,16 @@ def create_action_presentation(action_class) end # @return [Action::PlanPhase] - def plan_action(plan_action, *args, &block) + def plan_action(plan_action, *args, **kwargs, &block) Match! plan_action.phase, Action::Plan - plan_action.execute *args, &block + plan_action.execute *args, **kwargs, &block raise plan_action.error if plan_action.error plan_action end - def create_and_plan_action(action_class, *args, &block) - plan_action create_action(action_class), *args, &block + def create_and_plan_action(action_class, *args, **kwargs, &block) + plan_action create_action(action_class), *args, **kwargs, &block end def plan_events(world, delayed_events) diff --git a/lib/dynflow/world.rb b/lib/dynflow/world.rb index 7f3e54cb2..e78a4d287 100644 --- a/lib/dynflow/world.rb +++ b/lib/dynflow/world.rb @@ -200,9 +200,9 @@ def delay_with_options(action_class:, args:, kwargs: {}, delay_options:, id: nil Scheduled[execution_plan.id] end - def plan_elsewhere(action_class, *args) + def plan_elsewhere(action_class, *args, **kwargs) execution_plan = ExecutionPlan.new(self, nil) - execution_plan.delay(nil, action_class, {}, *args) + execution_plan.delay(nil, action_class, {}, *args, **kwargs) plan_request(execution_plan.id) Scheduled[execution_plan.id]