Skuld.Effects.EffectLogger.EnvStateSnapshot (skuld v0.1.15)
View SourceA serializable snapshot of env.state for cold resume.
The env.state map uses tuple keys like {Module, key} which aren't
JSON-serializable. This struct captures a snapshot with string keys
for serialization, and can restore the original format on deserialization.
Key Format
Tuple keys {Elixir.Module, :key} are encoded as "Elixir.Module::key".
Filtering
EffectLogger's internal state keys are filtered out when capturing:
- Log state key: would create circular reference (log contains snapshot)
- Resume value key: only needed during active resume, not for persistence
- State keys filter: internal config that doesn't survive JSON round-trip
Example
env_state = %{
{Skuld.Effects.State, Skuld.Effects.State} => 42,
{Skuld.Effects.EffectLogger, :log} => %Log{...}
}
snapshot = EnvStateSnapshot.capture(env_state)
# => %EnvStateSnapshot{entries: %{"Elixir.Skuld.Effects.State::Elixir.Skuld.Effects.State" => 42}}
restored = EnvStateSnapshot.restore(snapshot)
# => %{{Skuld.Effects.State, Skuld.Effects.State} => 42}
Summary
Functions
Capture a snapshot of env.state for serialization.
Reconstruct from decoded JSON map.
Restore env.state from a snapshot.
Types
Functions
Capture a snapshot of env.state for serialization.
Filters out EffectLogger's internal state and converts tuple keys to strings.
Options
:state_keys- List of state keys to include. Default:allcaptures everything. Keys should be in the format{Module, tag}as used in env.state.
Examples
# Capture all state
EnvStateSnapshot.capture(env_state)
# Capture only specific State effect keys
EnvStateSnapshot.capture(env_state, state_keys: [
{Skuld.Effects.State, MyApp.Counter}
])
Reconstruct from decoded JSON map.
Restore env.state from a snapshot.
Converts string keys back to tuple format.