Skip to content

Commit 8a5ab06

Browse files
committed
ref(client): Split client flush into seperate function for readability
GH-4601
1 parent 9da7be8 commit 8a5ab06

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

sentry_sdk/client.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,6 @@ def flush( # type: ignore[override]
995995
:param callback: Is invoked with the number of pending events and the configured timeout.
996996
"""
997997
if self.transport is not None:
998-
if timeout is None:
999-
timeout = self.options["shutdown_timeout"]
1000-
1001998
if isinstance(self.transport, AsyncHttpTransport) and hasattr(
1002999
self.transport, "loop"
10031000
):
@@ -1009,27 +1006,37 @@ def flush( # type: ignore[override]
10091006
logger.warning("Event loop not running, aborting flush.")
10101007
return None
10111008
else:
1012-
self.session_flusher.flush()
1009+
self._flush_sync(timeout, callback)
1010+
return None
10131011

1014-
if self.log_batcher is not None:
1015-
self.log_batcher.flush()
1012+
def _flush_sync(
1013+
self, timeout: Optional[float], callback: Optional[Callable[[int, float], None]]
1014+
) -> None:
1015+
"""Synchronous flush implementation."""
1016+
if timeout is None:
1017+
timeout = self.options["shutdown_timeout"]
10161018

1017-
self.transport.flush(timeout=timeout, callback=callback)
1018-
return None
1019+
self._flush_components()
1020+
if self.transport is not None:
1021+
self.transport.flush(timeout=timeout, callback=callback)
10191022

10201023
async def _flush_async(
10211024
self, timeout: Optional[float], callback: Optional[Callable[[int, float], None]]
10221025
) -> None:
1023-
1026+
"""Asynchronous flush implementation."""
10241027
if timeout is None:
10251028
timeout = self.options["shutdown_timeout"]
10261029

1030+
self._flush_components()
1031+
if self.transport is not None:
1032+
flush_task = self.transport.flush(timeout=timeout, callback=callback) # type: ignore
1033+
if flush_task is not None:
1034+
await flush_task
1035+
1036+
def _flush_components(self) -> None:
10271037
self.session_flusher.flush()
10281038
if self.log_batcher is not None:
10291039
self.log_batcher.flush()
1030-
flush_task = self.transport.flush(timeout=timeout, callback=callback) # type: ignore
1031-
if flush_task is not None:
1032-
await flush_task
10331040

10341041
def __enter__(self) -> _Client:
10351042
return self

0 commit comments

Comments
 (0)