Example #1
0
 async def reinitialize(
     self,
     connection: Connection[StreamingCommitCursorRequest,
                            StreamingCommitCursorResponse],
     last_error: Optional[GoogleAPICallError],
 ):
     await self._stop_loopers()
     await connection.write(
         StreamingCommitCursorRequest(initial=self._initial))
     response = await connection.read()
     if "initial" not in response:
         self._connection.fail(
             FailedPrecondition(
                 "Received an invalid initial response on the publish stream."
             ))
     if self._outstanding_commits:
         # Roll up outstanding commits
         rollup: List[WorkItem[Cursor, None]] = []
         for batch in self._outstanding_commits:
             for item in batch:
                 rollup.append(item)
         self._outstanding_commits = [rollup]
         req = StreamingCommitCursorRequest()
         req.commit.cursor = rollup[-1].request
         await connection.write(req)
     self._start_loopers()
 async def _flush(self):
     if self._next_to_commit is None:
         return
     req = StreamingCommitCursorRequest()
     req.commit.cursor = self._next_to_commit
     self._outstanding_commits.append(self._next_to_commit)
     self._next_to_commit = None
     self._empty.clear()
     try:
         await self._connection.write(req)
     except GoogleAPICallError as e:
         _LOGGER.debug(f"Failed commit on stream: {e}")
Example #3
0
 async def _flush(self):
     batch = self._batcher.flush()
     if not batch:
         return
     self._outstanding_commits.append(batch)
     req = StreamingCommitCursorRequest()
     req.commit.cursor = batch[-1].request
     try:
         await self._connection.write(req)
     except GoogleAPICallError as e:
         _LOGGER.debug(f"Failed commit on stream: {e}")
         self._fail_if_retrying_failed()
 async def reinitialize(
     self,
     connection: Connection[StreamingCommitCursorRequest,
                            StreamingCommitCursorResponse],
 ):
     await connection.write(
         StreamingCommitCursorRequest(initial=self._initial))
     response = await connection.read()
     if "initial" not in response:
         self._connection.fail(
             FailedPrecondition(
                 "Received an invalid initial response on the publish stream."
             ))
     if self._next_to_commit is None:
         if self._outstanding_commits:
             self._next_to_commit = self._outstanding_commits[-1]
     self._outstanding_commits = []
     self._start_loopers()