Nous.Workflow.Scratch (nous v0.15.8)

View Source

Optional per-workflow ETS table for large/binary data exchange between steps.

Use when workflow steps produce large data (fetched HTML, images, CSVs) that shouldn't be copied through the immutable state pipeline. The scratch table is created lazily and auto-cleaned on workflow completion.

Usage

Enable via scratch: true option when running a workflow:

{:ok, state} = Nous.Workflow.run(graph, %{}, scratch: true)

Inside a transform or handler:

# Write large data
Nous.Workflow.Scratch.put(scratch, :raw_html, large_binary)

# Read it later
html = Nous.Workflow.Scratch.get(scratch, :raw_html)

The scratch reference is available in state.metadata.scratch.

Summary

Functions

Clean up the scratch ETS table. Called automatically on workflow completion.

Delete a key from the scratch space.

Retrieve a value from the scratch space.

Create a new scratch space (lazily — ETS table created on first write).

Store a value in the scratch space.

Types

t()

@type t() :: %Nous.Workflow.Scratch{id: String.t(), table: :ets.tid() | nil}

Functions

cleanup(scratch)

@spec cleanup(t()) :: :ok

Clean up the scratch ETS table. Called automatically on workflow completion.

delete(scratch, key)

@spec delete(t(), term()) :: :ok

Delete a key from the scratch space.

get(scratch, key, default \\ nil)

@spec get(t(), term(), term()) :: term()

Retrieve a value from the scratch space.

new()

@spec new() :: t()

Create a new scratch space (lazily — ETS table created on first write).

put(scratch, key, value)

@spec put(t(), term(), term()) :: t()

Store a value in the scratch space.