File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1010from tenacity .wait import wait_fixed
1111
1212from .async_utils import cancel_wait_task , delayed_start
13- from .logging_utils import log_context
13+ from .logging_utils import log_catch , log_context
1414
1515_logger = logging .getLogger (__name__ )
1616
@@ -84,7 +84,8 @@ class _InternalTryAgain(TryAgain):
8484 )
8585 @functools .wraps (func )
8686 async def _wrapper (* args : P .args , ** kwargs : P .kwargs ) -> None :
87- await func (* args , ** kwargs )
87+ with log_catch (_logger , reraise = True ):
88+ await func (* args , ** kwargs )
8889 raise _InternalTryAgain
8990
9091 return _wrapper
Original file line number Diff line number Diff line change 66
77import asyncio
88import datetime
9+ import logging
910from collections .abc import AsyncIterator , Awaitable , Callable
1011from typing import Final
1112from unittest import mock
@@ -204,3 +205,19 @@ async def _func() -> None:
204205 await task
205206
206207 assert mock_func .call_count > 1
208+
209+
210+ async def test_periodic_task_logs_error (
211+ mock_background_task : mock .AsyncMock ,
212+ task_interval : datetime .timedelta ,
213+ caplog : pytest .LogCaptureFixture ,
214+ ):
215+ mock_background_task .side_effect = RuntimeError ("Test error" )
216+
217+ with caplog .at_level (logging .ERROR ):
218+ async with periodic_task (
219+ mock_background_task , interval = task_interval , task_name = "test_task"
220+ ):
221+ await asyncio .sleep (2 * task_interval .total_seconds ())
222+
223+ assert "Test error" in caplog .text
You can’t perform that action at this time.
0 commit comments