backport broker changes

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt
2025-06-13 15:53:57 +02:00
parent 5b8681b1af
commit c62e1d5457

View File

@ -240,6 +240,10 @@ class _PostgresConsumer(Consumer):
self._listen_connection: DatabaseWrapper | None = None self._listen_connection: DatabaseWrapper | None = None
self.postgres_channel = channel_name(self.queue_name, ChannelIdentifier.ENQUEUE) self.postgres_channel = channel_name(self.queue_name, ChannelIdentifier.ENQUEUE)
# Override because dramatiq doesn't allow us setting this manually
# TODO: turn it into a setting
self.timeout = 30000 // 1000
@property @property
def connection(self) -> DatabaseWrapper: def connection(self) -> DatabaseWrapper:
return connections[self.db_alias] return connections[self.db_alias]
@ -313,13 +317,12 @@ class _PostgresConsumer(Consumer):
) )
.values_list("message_id", flat=True) .values_list("message_id", flat=True)
) )
channel = channel_name(self.queue_name, ChannelIdentifier.ENQUEUE) return [Notify(pid=0, channel=self.postgres_channel, payload=item) for item in notifies]
return [Notify(pid=0, channel=channel, payload=item) for item in notifies]
def _poll_for_notify(self): def _poll_for_notify(self):
with self.listen_connection.cursor() as cursor: with self.listen_connection.cursor() as cursor:
self.logger.debug(f"timeout is {self.timeout}") self.logger.debug(f"timeout is {self.timeout}")
notifies = list(cursor.connection.notifies(timeout=self.timeout)) notifies = list(cursor.connection.notifies(timeout=self.timeout, stop_after=1))
self.logger.debug( self.logger.debug(
f"Received {len(notifies)} postgres notifies on channel {self.postgres_channel}" f"Received {len(notifies)} postgres notifies on channel {self.postgres_channel}"
) )