AshScenario.Scenario.Executor behaviour (ash_scenario v0.6.0)

View Source

Shared execution logic for creating resources from prototypes.

This module contains the common execution logic used by both Runner (database persistence) and StructBuilder (struct creation without persistence). It uses a strategy pattern to delegate the actual resource creation to different implementations.

Summary

Callbacks

Defines the behaviour that execution strategies must implement.

Functions

Execute all prototypes defined for a resource module.

Execute a list of prototypes using the specified strategy.

Execute a single prototype and return the created resource.

Callbacks

create_resource(module, attributes, opts)

@callback create_resource(module :: module(), attributes :: map(), opts :: keyword()) ::
  {:ok, struct()} | {:error, any()}

Defines the behaviour that execution strategies must implement.

wrap_execution(prototypes, opts, execution_fn)

@callback wrap_execution(
  prototypes :: list(),
  opts :: keyword(),
  execution_fn :: function()
) :: {:ok, map()} | {:error, any()}

Functions

execute_all_prototypes(resource_module, opts, strategy)

Execute all prototypes defined for a resource module.

execute_prototypes(prototype_refs, opts, strategy)

Execute a list of prototypes using the specified strategy.

Parameters

  • prototype_refs - List of prototype references to execute
  • opts - Options for execution
  • strategy - Module implementing the execution strategy behaviour

Returns

  • {:ok, map()} - Map of created resources keyed by {module, ref}
  • {:error, reason} - Error if execution fails

execute_single_prototype(resource_module, prototype_name, opts, strategy)

Execute a single prototype and return the created resource.