Coverage for async_durable_execution/_operation/wait.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-08-30 23:43 +0000

1"""User-facing durable wait operation.""" 

2 

3from __future__ import annotations 

4 

5import asyncio 

6 

7from .._core import ( 

8 Duration, 

9 OperationSubType, 

10 ValidationError, 

11 duration_to_seconds, 

12) 

13from ..extension import get_extension_context 

14 

15 

16def wait(duration: Duration, *, name: str | None = None) -> asyncio.Task[None]: 

17 """Suspend the durable execution for at least the given duration. 

18 

19 Args: 

20 duration: Seconds or timedelta to pause. Must be at least one second. 

21 name: Optional operation name shown in execution history. 

22 """ 

23 seconds = duration_to_seconds(duration) 

24 if seconds < 1: 

25 msg = "duration must be at least 1 second" 

26 raise ValidationError(msg) 

27 

28 return ( 

29 get_extension_context() 

30 ._reserve_sdk_operation( # noqa: SLF001 

31 name, 

32 ) 

33 ._run_wait( # noqa: SLF001 

34 duration, 

35 sub_type=OperationSubType.WAIT, 

36 ) 

37 ) 

38 

39 

40__all__ = ["wait"]