glixir/supervisor

Dynamic supervisor support for runtime process management

This module provides a Gleam-friendly interface to Elixir’s DynamicSupervisor, using our Elixir helper module for clean data conversion.

Types

pub type ChildCounts {
  ChildCounts(
    specs: Int,
    active: Int,
    supervisors: Int,
    workers: Int,
  )
}

Constructors

  • ChildCounts(
      specs: Int,
      active: Int,
      supervisors: Int,
      workers: Int,
    )
pub type ChildInfoResult {
  ChildInfo(
    id: dynamic.Dynamic,
    child: ChildStatus,
    child_type: ChildType,
    modules: ChildModules,
  )
}

Constructors

pub type ChildModules {
  ModulesDynamic
  ModulesList(modules: List(atom.Atom))
  ModulesEmpty
}

Constructors

  • ModulesDynamic
  • ModulesList(modules: List(atom.Atom))
  • ModulesEmpty
pub type ChildOperationError {
  Running
  Restarting
  NotFound
  SimpleOneForOne
  OtherError(reason: dynamic.Dynamic)
}

Constructors

  • Running
  • Restarting
  • NotFound
  • SimpleOneForOne
  • OtherError(reason: dynamic.Dynamic)
pub type ChildStatus {
  ChildPid(pid: process.Pid)
  ChildRestarting
  ChildUndefined
}

Constructors

  • ChildPid(pid: process.Pid)
  • ChildRestarting
  • ChildUndefined
pub type ChildType {
  Worker
  SupervisorChild
}

Constructors

  • Worker
  • SupervisorChild
pub type DeleteChildResult {
  DeleteChildOk
  DeleteChildError(reason: ChildOperationError)
}

Constructors

pub type DynamicChildResult {
  DynamicStartChildOk(pid: process.Pid)
  DynamicStartChildError(reason: dynamic.Dynamic)
}

Constructors

pub type DynamicSupervisorResult {
  DynamicSupervisorOk(pid: process.Pid)
  DynamicSupervisorError(reason: dynamic.Dynamic)
}

Constructors

pub type DynamicTerminateResult {
  DynamicTerminateChildOk
  DynamicTerminateChildError(reason: dynamic.Dynamic)
}

Constructors

  • DynamicTerminateChildOk
  • DynamicTerminateChildError(reason: dynamic.Dynamic)
pub type RestartChildResult {
  RestartChildOk(pid: process.Pid)
  RestartChildOkAlreadyStarted(pid: process.Pid)
  RestartChildError(reason: ChildOperationError)
}

Constructors

Child restart strategy

pub type RestartStrategy {
  Permanent
  Temporary
  Transient
}

Constructors

  • Permanent
  • Temporary
  • Transient
pub type SimpleChildSpec {
  SimpleChildSpec(
    id: String,
    start_module: atom.Atom,
    start_function: atom.Atom,
    start_args: List(dynamic.Dynamic),
    restart: RestartStrategy,
    shutdown_timeout: Int,
    child_type: ChildType,
  )
}

Constructors

Opaque type representing a supervisor process

pub opaque type Supervisor

Errors from supervisor operations

pub type SupervisorError {
  StartError(reason: String)
  ChildStartError(id: String, reason: String)
  ChildNotFound(id: String)
  AlreadyStarted(id: String)
  InvalidChildSpec(reason: String)
}

Constructors

  • StartError(reason: String)
  • ChildStartError(id: String, reason: String)
  • ChildNotFound(id: String)
  • AlreadyStarted(id: String)
  • InvalidChildSpec(reason: String)
pub type TerminateChildResult {
  TerminateChildOk
  TerminateChildError(reason: ChildOperationError)
}

Constructors

Values

pub fn child_spec(
  id: String,
  module: String,
  function: String,
  args: List(dynamic.Dynamic),
) -> SimpleChildSpec

Create a simple child specification - the easy way to define children

pub fn child_spec_with_restart(
  id: String,
  module: String,
  function: String,
  args: List(dynamic.Dynamic),
  restart: RestartStrategy,
) -> SimpleChildSpec

Create a child spec with custom restart strategy

pub fn count_dynamic_children(
  supervisor: Supervisor,
) -> ChildCounts

Count dynamic children by type and status

pub fn delete_child(
  supervisor: Supervisor,
  child_id: String,
) -> DeleteChildResult

Delete a child specification from the supervisor

pub fn restart_child(
  supervisor: Supervisor,
  child_id: String,
) -> RestartChildResult

Restart a child process

pub fn start_dynamic_child(
  supervisor: Supervisor,
  spec: SimpleChildSpec,
) -> Result(process.Pid, String)

Start a child in a DynamicSupervisor

pub fn start_dynamic_supervisor_named(
  name: String,
) -> Result(Supervisor, SupervisorError)

Start a named dynamic supervisor

pub fn start_dynamic_supervisor_simple(
  ,
) -> Result(Supervisor, SupervisorError)

Start a simple dynamic supervisor with defaults

pub fn terminate_child(
  supervisor: Supervisor,
  child_id: String,
) -> TerminateChildResult

Terminate a child process

pub fn terminate_dynamic_child(
  supervisor: Supervisor,
  child_pid: process.Pid,
) -> Result(Nil, String)

Terminate a dynamic child process

pub fn which_dynamic_children(
  supervisor: Supervisor,
) -> List(ChildInfoResult)

Get information about all dynamic children

Search Document