def get_next_txn(self, txn: LoggingTransaction): """ Usage: stream_id = stream_id_gen.get_next(txn) # ... persist event ... """ next_id = self._load_next_id_txn(txn) with self._lock: self._unfinished_ids.add(next_id) txn.call_after(self._mark_id_as_finished, next_id) txn.call_on_exception(self._mark_id_as_finished, next_id) # Update the `stream_positions` table with newly updated stream # ID (unless self._writers is not set in which case we don't # bother, as nothing will read it). # # We only do this on the success path so that the persisted current # position points to a persisted row with the correct instance name. if self._writers: txn.call_after( run_as_background_process, "MultiWriterIdGenerator._update_table", self._db.runInteraction, "MultiWriterIdGenerator._update_table", self._update_stream_positions_table_txn, ) return self._return_factor * next_id
def get_next_txn(self, txn: LoggingTransaction) -> int: """ Usage: stream_id = stream_id_gen.get_next(txn) # ... persist event ... """ # If we have a list of instances that are allowed to write to this # stream, make sure we're in it. if self._writers and self._instance_name not in self._writers: raise Exception("Tried to allocate stream ID on non-writer") next_id = self._load_next_id_txn(txn) txn.call_after(self._mark_id_as_finished, next_id) txn.call_on_exception(self._mark_id_as_finished, next_id) # Update the `stream_positions` table with newly updated stream # ID (unless self._writers is not set in which case we don't # bother, as nothing will read it). # # We only do this on the success path so that the persisted current # position points to a persisted row with the correct instance name. if self._writers: txn.call_after( run_as_background_process, "MultiWriterIdGenerator._update_table", self._db.runInteraction, "MultiWriterIdGenerator._update_table", self._update_stream_positions_table_txn, ) return self._return_factor * next_id
def get_next_txn(self, txn: LoggingTransaction): """ Usage: stream_id = stream_id_gen.get_next(txn) # ... persist event ... """ next_id = self._load_next_id_txn(txn) with self._lock: self._unfinished_ids.add(next_id) txn.call_after(self._mark_id_as_finished, next_id) txn.call_on_exception(self._mark_id_as_finished, next_id) return next_id
def _test_txn(txn: LoggingTransaction) -> None: txn.call_after(after_callback, 123, 456, extra=789) txn.call_on_exception(exception_callback, 987, 654, extra=321) func(txn)
def _test_txn(txn: LoggingTransaction) -> None: txn.call_after(after_callback, 123, 456, extra=789) txn.call_on_exception(exception_callback, 987, 654, extra=321) d.cancel() # Simulate a retryable failure on every attempt. raise self.db_pool.engine.module.OperationalError()