@@ -995,9 +995,6 @@ def flush( # type: ignore[override]
995
995
:param callback: Is invoked with the number of pending events and the configured timeout.
996
996
"""
997
997
if self .transport is not None :
998
- if timeout is None :
999
- timeout = self .options ["shutdown_timeout" ]
1000
-
1001
998
if isinstance (self .transport , AsyncHttpTransport ) and hasattr (
1002
999
self .transport , "loop"
1003
1000
):
@@ -1009,27 +1006,37 @@ def flush( # type: ignore[override]
1009
1006
logger .warning ("Event loop not running, aborting flush." )
1010
1007
return None
1011
1008
else :
1012
- self .session_flusher .flush ()
1009
+ self ._flush_sync (timeout , callback )
1010
+ return None
1013
1011
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" ]
1016
1018
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 )
1019
1022
1020
1023
async def _flush_async (
1021
1024
self , timeout : Optional [float ], callback : Optional [Callable [[int , float ], None ]]
1022
1025
) -> None :
1023
-
1026
+ """Asynchronous flush implementation."""
1024
1027
if timeout is None :
1025
1028
timeout = self .options ["shutdown_timeout" ]
1026
1029
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 :
1027
1037
self .session_flusher .flush ()
1028
1038
if self .log_batcher is not None :
1029
1039
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
1033
1040
1034
1041
def __enter__ (self ) -> _Client :
1035
1042
return self
0 commit comments