Skip to content

Commit 1e7ae3b

Browse files
committed
1 parent 54748e7 commit 1e7ae3b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/v1/_base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def __init__(
1515
self,
1616
rpc_client: RabbitMQRPCClient,
1717
namespace: RPCNamespace,
18+
*,
1819
rpc_request_kwargs: dict[str, Any] | None = None,
1920
):
2021
self._rpc_client = rpc_client
2122
self._namespace = namespace
23+
# extra kwargs to be passed to every rpc request
2224
self._rpc_request_kwargs = rpc_request_kwargs or {}
2325

2426
async def _request(
@@ -27,12 +29,8 @@ async def _request(
2729
*,
2830
product_name: ProductName,
2931
user_id: UserID,
30-
**optional_kwargs: Any
32+
**optional_kwargs: Any,
3133
) -> Any:
32-
assert self._rpc_request_kwargs.keys().isdisjoint(optional_kwargs.keys()), (
33-
"Conflict between request extras and kwargs"
34-
"Please rename the conflicting keys."
35-
)
3634

3735
return await self._request_without_authentication(
3836
method_name,
@@ -45,6 +43,7 @@ async def _request(
4543
async def _request_without_authentication(
4644
self, method_name: RPCMethodName, *, product_name: ProductName, **kwargs: Any
4745
) -> Any:
46+
4847
assert self._rpc_request_kwargs.keys().isdisjoint(kwargs.keys()), (
4948
"Conflict between request extras and kwargs"
5049
"Please rename the conflicting keys."

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/v1/functions.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Functions RPC API subclient."""
22

3-
from typing import Literal, cast
3+
from typing import Annotated, Any, Literal, cast
44

55
from models_library.api_schemas_webserver.functions import (
66
Function,
@@ -28,17 +28,42 @@
2828
RegisteredFunctionJobWithStatus,
2929
)
3030
from models_library.products import ProductName
31+
from models_library.rabbitmq_basic_types import RPCNamespace
3132
from models_library.rest_ordering import OrderBy
3233
from models_library.rest_pagination import PageMetaInfoLimitOffset
3334
from models_library.users import UserID
34-
from pydantic import TypeAdapter
35+
from pydantic import PositiveInt, TypeAdapter
36+
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
3537

3638
from ._base import BaseRpcApi
3739

40+
_FUNCTION_RPC_TIMEOUT_SEC: Annotated[int, PositiveInt] = 30
41+
3842

3943
class FunctionsRpcApi(BaseRpcApi):
4044
"""RPC client for function-related operations."""
4145

46+
def __init__(
47+
self,
48+
rpc_client: RabbitMQRPCClient,
49+
namespace: RPCNamespace,
50+
rpc_request_kwargs: dict[str, Any] | None = None,
51+
):
52+
rpc_request_kwargs = rpc_request_kwargs or {}
53+
assert "timeout_s" not in rpc_request_kwargs, (
54+
"timeout_s should not be set in rpc_request_kwargs, "
55+
f"it is set by default to {_FUNCTION_RPC_TIMEOUT_SEC} seconds"
56+
)
57+
58+
super().__init__(
59+
rpc_client,
60+
namespace,
61+
rpc_request_kwargs={
62+
**rpc_request_kwargs,
63+
"timeout_s": _FUNCTION_RPC_TIMEOUT_SEC,
64+
},
65+
)
66+
4267
# pylint: disable=too-many-public-methods
4368

4469
async def register_function(

0 commit comments

Comments
 (0)