Search documentation of Orchid

# Orchid.Step.NestedStep (Orchid v0.3.3)

View Source

Encapsulates a complete Recipe as a standalone Step to implement nested operations.

This allows you to treat a complex sub-workflow as a single atomic step within a parent workflow.

### Required Options

- `:recipe` - The inner `Orchid.Recipe` struct to be executed.

### Optional Options

- `:input_map` - Parameter name mapping: `%{parent_name => child_name}`. Use this when the parent step input name differs from what the inner recipe expects.
- `:output_map` - Result name mapping: `%{child_name => parent_name}`. Use this to rename the inner recipe's output back to what the parent workflow expects.

The mapping direction follows the flow of data (Input: Parent -> Child; Output: Child -> Parent).

## Examples

    nested_step = {Orchid.Step.NestedStep,
      :parent_param, :parent_result_param,
      [
        recipe: inner_recipe,
        # Maps parent's :parent_param to child's :child_input
        input_map: %{parent_param: :child_input},
        # Maps child's :child_output back to :parent_result_param
        output_map: %{child_output: :parent_result_param}
      ]
    }

### Custom Nested Steps

If you need to define a custom step that behaves like a nested step (e.g., custom logic before/after the sub-recipe), you must place the inner recipe in the `:recipe` option and implement `nested?/0`:

    defmodule MyNested do
      use Orchid.Step

      # Tell the Scheduler to treat this as a nested step during traversals
      def nested?(), do: true

      def run(input, opts) do
        # ... custom logic ...
      end
    end

# Summary

## Functions

report(opts, progress, payload \\ nil)

Reports progress or status to the executor.

run(input_params, opts)

Callback implementation for `Orchid.Step.run/2`.

# Functions

# report(opts, progress, payload \\ nil)

Reports progress or status to the executor.

## Example

    def run(input, opts) do
      report(opts, :processing, "Start heavy calculation...")
      # ...
      report(opts, :uploading, 50)
      {:ok, result}
    end

# run(input_params, opts)

    @spec run(Orchid.Step.input(), Orchid.Step.step_options()) ::
      {:error, {:nested_step_execution_failed, term()}}
      | {:ok, Orchid.Step.output()}

Callback implementation for `Orchid.Step.run/2`.