pgcom.listener.Listener

class Listener(pool_size: int = 20, pre_ping: bool = False, max_reconnects: int = 3, **kwargs: str)[source]

Listener on the notification channel.

This class implements an asynchronous interaction with database offered by PostgreSQL commands LISTEN and NOTIFY.

Notifications are received after trigger is fired, the poll method can be used to check for the new notifications without wasting resources.

Methods create_notify_function and create_trigger present basic query constructors, which can be used to define a new trigger and a new function associated with this trigger. Some custom definitions can be done using execute method.

Parameters
  • pool_size – The maximum amount of connections the pool will support.

  • pre_ping – If True, the pool will emit a “ping” on the connection to test if the connection is alive. If not, the connection will be reconnected.

  • max_reconnects – The maximum amount of reconnects, defaults to 3.

Methods

create_notify_function(func_name, channel)

Create a function called by trigger.

create_trigger(table_name, func_name[, ...])

Create trigger.

execute(cmd[, values])

Execute a database operation (query or command).

poll(channel[, on_notify, on_timeout, ...])

Listen to the channel and activate callbacks on the notification.