m3resp.run_workflow#

m3resp.run_workflow(spec, *, session=None, eit_adapter=None, emg_adapter=None, extra_context=None, event_sink=None, cancellation_token=None, run_id=None)[source]#

Run a workflow’s ordered steps and return their results and records.

Captures and re-emits step warnings and records each executed step in the session’s processing history. A cancellation request is checked before and after each step, preserving completed work. Workflow failures preserve session changes made before the error.

Parameters:
  • spec (str | Path | dict[str, Any] | WorkflowSpec) – A WorkflowSpec, dictionary, or YAML/JSON file path.

  • session (M3Session | None) – Session to process and update; None creates a new session.

  • eit_adapter (Any) – EIT adapter used when creating a new session.

  • emg_adapter (Any) – EMG adapter used when creating a new session.

  • extra_context (dict[str, Any] | None) – Values supplied under context keys before execution. These keys are treated as available during structural validation.

  • event_sink (Callable[[dict[str, Any]], None] | None) – Optional callable receiving progress-event dictionaries for workflow and step starts, warnings, completion, failure and cancellation. It is called synchronously.

  • cancellation_token (CancellationToken | None) – Optional flag for stopping between steps.

  • run_id (str | None) – Optional run identifier; a new identifier is generated when unset.

Returns:

Live session, context values, resolved step descriptions,

execution records, timings in seconds and captured warnings. Status is succeeded or cancelled. An attached data-model recorder stores the run’s outputs and supplies processing_run_id. Export operations occur through declared steps; run_spec also applies outputs settings and writes run manifests.

Return type:

WorkflowResult

Raises:
  • WorkflowSpecError – If the spec or bindings are invalid, or a step returns an invalid output dictionary or omits a declared output.

  • UnknownStepError – If the first structural error concerns an unknown step.

  • WorkflowExecutionError – If a step function raises; the original exception is available through __cause__ and gathered step records are retained.