Raxol.Core.ErrorRecovery.ContextManager (Raxol v2.0.1)

View Source

Manages context preservation across process restarts.

This module ensures that critical state and context information is preserved when processes are restarted, enabling faster recovery and reducing the impact of failures.

Features

  • Automatic context capture before process termination
  • Intelligent context merging on restoration
  • TTL-based context cleanup
  • Serializable context storage
  • Performance-optimized retrieval

Usage

# Store context for a process
ContextManager.store_context(:my_process, %{
  user_sessions: active_sessions,
  cached_data: important_cache,
  connection_state: conn_info
})

# Retrieve context after restart
context = ContextManager.get_context(:my_process)

Summary

Functions

Returns a specification to start this module under a supervisor.

Manually trigger cleanup of expired contexts.

Export all contexts for backup or analysis.

Retrieve context data for a process or component.

Get statistics about stored contexts.

Check if context exists for a key.

Import contexts from backup data.

Remove context data for a key.

Store context data for a process or component.

Update existing context data by merging with new data.

Types

context_data()

@type context_data() :: term()

context_entry()

@type context_entry() :: %{
  key: context_key(),
  data: context_data(),
  stored_at: DateTime.t(),
  ttl_ms: non_neg_integer(),
  access_count: non_neg_integer(),
  last_accessed: DateTime.t()
}

context_key()

@type context_key() :: term()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup_expired()

Manually trigger cleanup of expired contexts.

export_contexts()

Export all contexts for backup or analysis.

get_context(key)

Retrieve context data for a process or component.

get_stats()

Get statistics about stored contexts.

has_context?(key)

Check if context exists for a key.

import_contexts(contexts_data)

Import contexts from backup data.

remove_context(key)

Remove context data for a key.

start_link(init_opts \\ [])

store_context(key, data, opts \\ [])

Store context data for a process or component.

update_context(key, data, merge_fun \\ &Map.merge/2)

Update existing context data by merging with new data.