Electric.Connection.Manager (electric v1.0.15)

View Source

Custom initialisation and reconnection logic for database connections.

This module is esentially a supervisor for database connections, implemented as a GenServer. Unlike an OTP process supervisor, it includes additional functionality:

  • adjusting connection options based on the response from the database
  • monitoring connections and initiating a reconnection procedure
  • custom reconnection logic with exponential backoff
  • starting the shape consumer supervisor tree once a database connection pool has been initialized

Your OTP application should start a singleton connection manager under its main supervision tree:

children = [
  ...,
  {Electric.Connection.Manager,
   stack_id: ...,
   connection_opts: [...],
   replication_opts: [...],
   pool_opts: [...],
   timeline_opts: [...],
   shape_cache_opts: [...]}
]

Supervisor.start_link(children, strategy: :one_for_one)

Summary

Types

option()

@type option() ::
  {:stack_id, atom() | String.t()}
  | {:connection_opts, Keyword.t()}
  | {:replication_opts, Keyword.t()}
  | {:pool_opts, Keyword.t()}
  | {:timeline_opts, Keyword.t()}
  | {:shape_cache_opts, Keyword.t()}

options()

@type options() :: [option()]

status()

@type status() :: :waiting | :starting | :active

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

drop_replication_slot_on_stop(manager)

exclusive_connection_lock_acquired(manager)

exclusive_connection_lock_acquisition_failed(manager, error)

lock_connection_started(manager)

name(stack_id)

pg_info_looked_up(manager, pg_info)

ping(manager, timeout \\ 1000)

pool_name(stack_id)

replication_client_created_new_slot(manager)

replication_client_ready_to_stream(manager)

replication_client_started(manager)

replication_client_streamed_first_message(manager)

start_link(opts)

@spec start_link(options()) :: GenServer.on_start()