View Source Electric.ConnectionManager (electric v0.7.3)

Custom initialisation and reconnection logic for database connections.

This module is esentially a supervisor for database connections. But 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 replication connection has been established

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

children = [
  ...,
  {Electric.ConnectionManager,
   connection_opts: [...],
   replication_opts: [...],
   pool_opts: [...],
   log_collector: {LogCollector, [...]},
   shape_cache: {ShapeCache, [...]}}
  ...
]

Supervisor.start_link(children, strategy: :one_for_one)

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the version of the PostgreSQL server.

Returns the status of the connection manager.

Types

@type option() ::
  {:connection_opts, Keyword.t()}
  | {:replication_opts, Keyword.t()}
  | {:pool_opts, Keyword.t()}
  | {:timeline_opts, Keyword.t()}
  | {:log_collector, {module(), Keyword.t()}}
  | {:shape_cache, {module(), Keyword.t()}}
@type options() :: [option()]
@type status() :: :waiting | :starting | :active

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec get_pg_version(GenServer.server()) :: float()

Returns the version of the PostgreSQL server.

@spec get_status(GenServer.server()) :: status()

Returns the status of the connection manager.

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