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

8 statements  

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

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

2 

3from __future__ import annotations 

4 

5import asyncio 

6 

7from .._core import Duration, OperationSubType, SerDes 

8from .._primitive.callback import Callback, CallbackError 

9from ..extension import get_extension_context 

10 

11 

12def create_callback( 

13 *, 

14 name: str | None = None, 

15 timeout: Duration | None = None, 

16 heartbeat_timeout: Duration | None = None, 

17 serdes: SerDes | None = None, 

18) -> asyncio.Task[Callback]: 

19 """Create a durable callback handle that external systems can complete later. 

20 

21 Args: 

22 name: Optional durable operation name. 

23 timeout: Optional maximum time to wait for callback completion. 

24 heartbeat_timeout: Optional maximum time to wait between callback heartbeats. 

25 serdes: Optional serializer for callback results. 

26 """ 

27 return ( 

28 get_extension_context() 

29 ._reserve_sdk_operation( # noqa: SLF001 

30 name, 

31 ) 

32 ._run_create_callback( # noqa: SLF001 

33 sub_type=OperationSubType.CALLBACK, 

34 timeout=timeout, 

35 heartbeat_timeout=heartbeat_timeout, 

36 serdes=serdes, 

37 ) 

38 ) 

39 

40 

41__all__ = ["Callback", "CallbackError", "create_callback"]