Limen.Instance (limen v0.2.1)

Copy Markdown View Source

A running Limen instance: its configuration and handles to its state.

When an instance starts, it creates its tables and counters and publishes this struct in :persistent_term under its name. The request path reads it once, at the start of each request, and hands it down in the Limen.Context: finding an instance never involves a process, a registry or an ETS lookup.

Changing an instance's configuration at runtime (update_config/3) republishes the struct, which triggers a global GC scan in the runtime: treat it as an operator action, not something to do per request.

Summary

Functions

Returns the running instance name.

Returns the running instance name, or nil.

The instance name given by an :instance or an :otp_app option, as Limen.Plug and the socket checks take it.

Validates and changes one configuration option of a running instance.

The pid of the process with child id id in the instance's supervisor.

Types

t()

@type t() :: %Limen.Instance{
  config: Limen.Config.t(),
  cookie_pattern: :binary.cp() | nil,
  log: map() | nil,
  maze: :atomics.atomics_ref() | nil,
  name: atom(),
  pass_binding: [:prefix | :ja4 | :user_agent] | nil,
  replay: term(),
  state: map() | nil,
  stats: :counters.counters_ref() | nil,
  supervisor: pid() | nil,
  tarpit: :atomics.atomics_ref() | nil
}

Functions

fetch!(instance)

@spec fetch!(atom() | t()) :: t()

Returns the running instance name.

Raises if it is not running.

get(name)

@spec get(atom()) :: t() | nil

Returns the running instance name, or nil.

name!(opts)

@spec name!(keyword()) :: atom()

The instance name given by an :instance or an :otp_app option, as Limen.Plug and the socket checks take it.

update_config(name, key, value)

@spec update_config(atom(), atom(), term()) :: :ok

Validates and changes one configuration option of a running instance.

Keyword lists are merged into the option's current value, see Limen.Config.update/3. Raises ArgumentError on an invalid value, or for an option only read when the instance starts.

whereis(instance, id)

@spec whereis(atom() | t(), module()) :: pid() | nil

The pid of the process with child id id in the instance's supervisor.