async def _flush(self): batch = self._batcher.flush() if not batch: return self._outstanding_writes.append(batch) aggregate = PublishRequest() aggregate.message_publish_request.messages = [item.request for item in batch] try: await self._connection.write(aggregate) except GoogleAPICallError as e: _LOGGER.debug(f"Failed publish on stream: {e}") self._fail_if_retrying_failed()
async def reinitialize( self, connection: Connection[PublishRequest, PublishResponse], last_error: Optional[GoogleAPICallError], ): await self._stop_loopers() await connection.write(PublishRequest(initial_request=self._initial)) response = await connection.read() if "initial_response" not in response: self._connection.fail( FailedPrecondition( "Received an invalid initial response on the publish stream." ) ) for batch in self._outstanding_writes: aggregate = PublishRequest() aggregate.message_publish_request.messages = [ item.request for item in batch ] await connection.write(aggregate) self._start_loopers()