From 6181fb151d2fa494a50999fd734b74fab31a4fdf Mon Sep 17 00:00:00 2001 From: Santiago Diaz Date: Wed, 18 Mar 2026 11:35:11 -0300 Subject: [PATCH] fix linters --- .rubocop.yml | 3 +++ lib/mars/workflows/parallel.rb | 43 ++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index eefff36..0a94234 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,8 @@ Metrics/MethodLength: Enabled: true Exclude: - "lib/mars/workflows/parallel.rb" + - "lib/mars/rendering/html.rb" + - "lib/mars/workflows/sequential.rb" Metrics/ParameterLists: Enabled: true @@ -26,6 +28,7 @@ Metrics/AbcSize: Enabled: true Exclude: - "lib/mars/rendering/graph/parallel_workflow.rb" + - "lib/mars/workflows/sequential.rb" Style/Documentation: Enabled: false diff --git a/lib/mars/workflows/parallel.rb b/lib/mars/workflows/parallel.rb index 12c5d41..4e147d2 100644 --- a/lib/mars/workflows/parallel.rb +++ b/lib/mars/workflows/parallel.rb @@ -19,17 +19,20 @@ def run(input) raise AggregateError, errors if errors.any? context.merge(child_contexts) + aggregate_results(results) + end + + private + + attr_reader :steps, :aggregator + def aggregate_results(results) has_global_halt = results.any? { |r| r.is_a?(Halt) && r.global? } unwrapped = results.map { |r| r.is_a?(Halt) ? r.result : r } result = aggregator.run(unwrapped) has_global_halt ? Halt.new(result, scope: :global) : result end - private - - attr_reader :steps, :aggregator - def execute_steps(context, errors, child_contexts) Async do |workflow| tasks = steps.map do |step| @@ -37,20 +40,7 @@ def execute_steps(context, errors, child_contexts) child_contexts << child_ctx workflow.async do - step.run_before_hooks(child_ctx) - - step_input = step.formatter.format_input(child_ctx) - result = step.run(step_input) - - if result.is_a?(Halt) - step.run_after_hooks(child_ctx, result) - result - else - formatted = step.formatter.format_output(result) - child_ctx.record(step.name, formatted) - step.run_after_hooks(child_ctx, formatted) - formatted - end + workflow_step(step, child_ctx) rescue StandardError => e errors << { error: e, step_name: step.name } end @@ -60,6 +50,23 @@ def execute_steps(context, errors, child_contexts) end.result end + def workflow_step(step, child_ctx) + step.run_before_hooks(child_ctx) + + step_input = step.formatter.format_input(child_ctx) + result = step.run(step_input) + + if result.is_a?(Halt) + step.run_after_hooks(child_ctx, result) + result + else + formatted = step.formatter.format_output(result) + child_ctx.record(step.name, formatted) + step.run_after_hooks(child_ctx, formatted) + formatted + end + end + def ensure_context(input) input.is_a?(ExecutionContext) ? input : ExecutionContext.new(input: input) end