ExMemvid.EncoderSupervisor (ex_memvid v0.1.2)

This supervisor provides a robust way to spawn, monitor, and manage individual encoder state machines. Each encoder process is isolated and can fail independently without affecting other encoding operations.

Features

  • Process Isolation: Each encoder runs in its own supervised process
  • Fault Tolerance: Failed encoders don't affect other running encoders
  • Dynamic Management: Start and stop encoders on demand
  • Resource Cleanup: Automatic cleanup of failed or completed processes
  • Process Registry: Optional registration of encoders by name

Usage

# Start an encoder with automatic naming
{:ok, pid} = ExMemvid.EncoderSupervisor.start_encoder(
  index_name: "document_001",
  config: %ExMemvid.Config{codec: :h264}
)

# Start an encoder with custom name
{:ok, pid} = ExMemvid.EncoderSupervisor.start_encoder(
  index_name: "document_002", 
  config: config,
  name: {:via, Registry, {ExMemvid.Registry, "my_encoder"}}
)

# Stop a specific encoder
:ok = ExMemvid.EncoderSupervisor.stop_encoder(pid)

# List all running encoders
encoders = ExMemvid.EncoderSupervisor.list_encoders()

Summary

Functions

Returns a specification to start this module under a supervisor.

Counts the number of running encoder processes.

Gets detailed information about all running encoders including their current state.

Lists all currently running encoder processes.

Starts a new encoder state machine under supervision.

Starts the encoder supervisor.

Stops all running encoder processes.

Stops an encoder process.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count_encoders()

@spec count_encoders() :: non_neg_integer()

Counts the number of running encoder processes.

get_encoders_info()

@spec get_encoders_info() :: %{required(pid()) => {atom(), map()}}

Gets detailed information about all running encoders including their current state.

Returns a map with encoder PIDs as keys and their state information as values.

list_encoders()

@spec list_encoders() :: [tuple()]

Lists all currently running encoder processes.

Returns a list of {id, pid, type, modules} tuples for each running encoder.

start_encoder(opts)

@spec start_encoder(keyword()) :: DynamicSupervisor.on_start_child()

Starts a new encoder state machine under supervision.

Options

  • :index_name - Unique identifier for the encoder (required)
  • :config - ExMemvid configuration (required)
  • :name - Optional process name for registration
  • :restart - Restart strategy (default: :temporary)
  • :shutdown - Shutdown timeout (default: 5000)

Examples

# Basic encoder
{:ok, pid} = ExMemvid.EncoderSupervisor.start_encoder(
  index_name: "doc_001",
  config: %ExMemvid.Config{}
)

# Named encoder with custom restart strategy
{:ok, pid} = ExMemvid.EncoderSupervisor.start_encoder(
  index_name: "doc_002",
  config: config,
  name: MyEncoder,
  restart: :transient
)

start_link(init_arg)

Starts the encoder supervisor.

stop_all_encoders()

@spec stop_all_encoders() :: :ok

Stops all running encoder processes.

This is useful for cleanup during application shutdown or testing.

stop_encoder(pid_or_name)

@spec stop_encoder(GenServer.server()) :: :ok | {:error, :not_found}

Stops an encoder process.

Examples

:ok = ExMemvid.EncoderSupervisor.stop_encoder(pid)
:ok = ExMemvid.EncoderSupervisor.stop_encoder(MyEncoder)