Close the connection, raise an exception if we were watching. The supported exceptions are already checked in the retry object so we don't need to do it here. After we disconnect the connection, it will try to reconnect and do a health check as part of the
(
self,
conn: AbstractConnection,
error: Exception,
failure_count: Optional[int] = None,
start_time: Optional[float] = None,
command_name: Optional[str] = None,
)
| 2001 | s.sha = immediate("SCRIPT LOAD", s.script) |
| 2002 | |
| 2003 | def _disconnect_raise_on_watching( |
| 2004 | self, |
| 2005 | conn: AbstractConnection, |
| 2006 | error: Exception, |
| 2007 | failure_count: Optional[int] = None, |
| 2008 | start_time: Optional[float] = None, |
| 2009 | command_name: Optional[str] = None, |
| 2010 | ) -> None: |
| 2011 | """ |
| 2012 | Close the connection, raise an exception if we were watching. |
| 2013 | |
| 2014 | The supported exceptions are already checked in the |
| 2015 | retry object so we don't need to do it here. |
| 2016 | |
| 2017 | After we disconnect the connection, it will try to reconnect and |
| 2018 | do a health check as part of the send_command logic(on connection level). |
| 2019 | """ |
| 2020 | if error and failure_count <= conn.retry.get_retries(): |
| 2021 | record_operation_duration( |
| 2022 | command_name=command_name, |
| 2023 | duration_seconds=time.monotonic() - start_time, |
| 2024 | server_address=getattr(conn, "host", None), |
| 2025 | server_port=getattr(conn, "port", None), |
| 2026 | db_namespace=str(conn.db), |
| 2027 | error=error, |
| 2028 | retry_attempts=failure_count, |
| 2029 | ) |
| 2030 | conn.disconnect() |
| 2031 | # if we were watching a variable, the watch is no longer valid |
| 2032 | # since this connection has died. raise a WatchError, which |
| 2033 | # indicates the user should retry this transaction. |
| 2034 | if self.watching: |
| 2035 | raise WatchError( |
| 2036 | f"A {type(error).__name__} occurred while watching one or more keys" |
| 2037 | ) |
| 2038 | |
| 2039 | def execute(self, raise_on_error: bool = True) -> List[Any]: |
| 2040 | """Execute all the commands in the current pipeline""" |
no test coverage detected