Skip to content

Commit b146e41

Browse files
author
Andrei Neagu
committed
removed unused client
1 parent a847424 commit b146e41

File tree

4 files changed

+14
-117
lines changed

4 files changed

+14
-117
lines changed

packages/service-library/src/servicelib/fastapi/long_running_tasks/_client.py

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import asyncio
22
import functools
33
import logging
4-
from abc import ABC, abstractmethod
54
from collections.abc import Awaitable, Callable
6-
from datetime import timedelta
75
from typing import Any, Final
86

97
from fastapi import FastAPI, status
@@ -15,15 +13,8 @@
1513
from tenacity.stop import stop_after_attempt
1614
from tenacity.wait import wait_exponential
1715

18-
from ...long_running_tasks import lrt_api
1916
from ...long_running_tasks.errors import GenericClientError
20-
from ...long_running_tasks.models import (
21-
ClientConfiguration,
22-
LRTNamespace,
23-
TaskId,
24-
TaskStatus,
25-
)
26-
from ...rabbitmq._client_rpc import RabbitMQRPCClient
17+
from ...long_running_tasks.models import ClientConfiguration, TaskId, TaskStatus
2718

2819
_DEFAULT_HTTP_REQUESTS_TIMEOUT: Final[PositiveFloat] = 15
2920

@@ -97,7 +88,7 @@ def retry_on_http_errors(
9788
assert asyncio.iscoroutinefunction(request_func)
9889

9990
@functools.wraps(request_func)
100-
async def request_wrapper(zelf: "BaseClient", *args, **kwargs) -> Any:
91+
async def request_wrapper(zelf: "HttpClient", *args, **kwargs) -> Any:
10192
async for attempt in AsyncRetrying(
10293
stop=stop_after_attempt(max_attempt_number=3),
10394
wait=wait_exponential(min=1),
@@ -115,79 +106,7 @@ async def request_wrapper(zelf: "BaseClient", *args, **kwargs) -> Any:
115106
return request_wrapper
116107

117108

118-
class BaseClient(ABC):
119-
120-
@property
121-
@abstractmethod
122-
def external_reference(self) -> str:
123-
pass
124-
125-
@abstractmethod
126-
async def get_task_status(
127-
self, task_id: TaskId, *, timeout: PositiveFloat | None = None # noqa: ASYNC109
128-
) -> TaskStatus:
129-
pass
130-
131-
@abstractmethod
132-
async def get_task_result(
133-
self, task_id: TaskId, *, timeout: PositiveFloat | None = None # noqa: ASYNC109
134-
) -> Any | None:
135-
pass
136-
137-
@abstractmethod
138-
async def remove_task(
139-
self, task_id: TaskId, *, timeout: PositiveFloat | None = None # noqa: ASYNC109
140-
) -> None:
141-
pass
142-
143-
144-
class RPCClient(BaseClient):
145-
def __init__(
146-
self, rabbitmq_rpc_client: RabbitMQRPCClient, lrt_namespace: LRTNamespace
147-
):
148-
self._rpc_client = rabbitmq_rpc_client
149-
self._lrt_namespace = lrt_namespace
150-
151-
@property
152-
def external_reference(self) -> str:
153-
return f"LRT_NAMESPACE:{self._lrt_namespace}"
154-
155-
async def get_task_status(
156-
self, task_id: TaskId, *, timeout: PositiveFloat | None = None # noqa: ASYNC109
157-
) -> TaskStatus:
158-
_ = timeout
159-
return await lrt_api.get_task_status(
160-
self._rpc_client, self._lrt_namespace, {}, task_id
161-
)
162-
163-
async def get_task_result(
164-
self, task_id: TaskId, *, timeout: PositiveFloat | None = None # noqa: ASYNC109
165-
) -> Any | None:
166-
_ = timeout
167-
return await lrt_api.get_task_result(
168-
self._rpc_client, self._lrt_namespace, {}, task_id
169-
)
170-
171-
async def remove_task(
172-
self,
173-
task_id: TaskId,
174-
*,
175-
timeout: PositiveFloat | None = None, # noqa: ASYNC109
176-
wait_for_removal: bool = True,
177-
cancellation_timeout: timedelta | None = None,
178-
) -> None:
179-
_ = timeout
180-
return await lrt_api.remove_task(
181-
self._rpc_client,
182-
self._lrt_namespace,
183-
{},
184-
task_id,
185-
wait_for_removal=wait_for_removal,
186-
cancellation_timeout=cancellation_timeout,
187-
)
188-
189-
190-
class HttpClient(BaseClient):
109+
class HttpClient:
191110
"""
192111
This is a client that aims to simplify the requests to get the
193112
status, result and/or cancel of a long running task.

packages/service-library/src/servicelib/fastapi/long_running_tasks/_context_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
TaskId,
1717
TaskStatus,
1818
)
19-
from ._client import BaseClient
19+
from ._client import HttpClient
2020

2121
_logger = logging.getLogger(__name__)
2222

@@ -70,7 +70,7 @@ async def update(
7070

7171
@asynccontextmanager
7272
async def periodic_task_result(
73-
client: BaseClient,
73+
client: HttpClient,
7474
task_id: TaskId,
7575
*,
7676
task_timeout: PositiveFloat,

packages/service-library/src/servicelib/fastapi/long_running_tasks/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
Provides a convenient way to return the result given a TaskId.
33
"""
44

5-
from ._client import BaseClient, HttpClient, RPCClient, setup
5+
from ._client import HttpClient, setup
66
from ._context_manager import periodic_task_result # attach to the same object!
77

88
__all__: tuple[str, ...] = (
9-
"BaseClient",
109
"HttpClient",
1110
"periodic_task_result",
12-
"RPCClient",
1311
"setup",
1412
)
1513
# nopycln: file

packages/service-library/tests/fastapi/long_running_tasks/test_long_running_tasks_context_manager.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
from servicelib.fastapi.long_running_tasks._context_manager import _ProgressManager
1414
from servicelib.fastapi.long_running_tasks._manager import FastAPILongRunningManager
1515
from servicelib.fastapi.long_running_tasks.client import (
16-
BaseClient,
1716
HttpClient,
18-
RPCClient,
1917
periodic_task_result,
2018
)
2119
from servicelib.fastapi.long_running_tasks.client import setup as setup_client
@@ -48,7 +46,7 @@
4846

4947

5048
async def _assert_task_removed(
51-
base_client: BaseClient, task_id: TaskId, router_prefix: str
49+
base_client: HttpClient, task_id: TaskId, router_prefix: str
5250
) -> None:
5351
with pytest.raises(
5452
(GenericClientError, TaskNotFoundError), match=f"No task with {task_id} found"
@@ -139,28 +137,10 @@ def mock_task_id() -> TaskId:
139137
return TypeAdapter(TaskId).validate_python("fake_task_id")
140138

141139

142-
@pytest.fixture(params=[RPCClient.__name__, HttpClient.__name__])
143-
def base_client(
144-
request: pytest.FixtureRequest, bg_task_app: FastAPI, async_client: AsyncClient
145-
) -> BaseClient:
146-
match request.param:
147-
case RPCClient.__name__:
148-
long_running_manager: FastAPILongRunningManager = (
149-
bg_task_app.state.long_running_manager
150-
)
151-
return RPCClient(
152-
long_running_manager.rpc_client, long_running_manager.lrt_namespace
153-
)
154-
case HttpClient.__name__:
155-
url = TypeAdapter(AnyHttpUrl).validate_python(
156-
"http://backgroud.testserver.io/"
157-
)
158-
return HttpClient(
159-
app=bg_task_app, async_client=async_client, base_url=f"{url}"
160-
)
161-
case _:
162-
msg = f"Client {request.param} not implemented"
163-
raise NotImplementedError(msg)
140+
@pytest.fixture()
141+
def base_client(bg_task_app: FastAPI, async_client: AsyncClient) -> HttpClient:
142+
url = TypeAdapter(AnyHttpUrl).validate_python("http://backgroud.testserver.io/")
143+
return HttpClient(app=bg_task_app, async_client=async_client, base_url=f"{url}")
164144

165145

166146
async def _create_and_get_taskid(async_client: AsyncClient, *, endpoint: str) -> TaskId:
@@ -172,7 +152,7 @@ async def _create_and_get_taskid(async_client: AsyncClient, *, endpoint: str) ->
172152

173153
async def test_task_result(
174154
async_client: AsyncClient,
175-
base_client: BaseClient,
155+
base_client: HttpClient,
176156
router_prefix: str,
177157
) -> None:
178158
task_id = await _create_and_get_taskid(async_client, endpoint="success")
@@ -190,7 +170,7 @@ async def test_task_result(
190170

191171
async def test_task_result_times_out(
192172
async_client: AsyncClient,
193-
base_client: BaseClient,
173+
base_client: HttpClient,
194174
router_prefix: str,
195175
) -> None:
196176
task_id = await _create_and_get_taskid(async_client, endpoint="success")
@@ -215,7 +195,7 @@ async def test_task_result_times_out(
215195
async def test_task_result_task_result_is_an_error(
216196
bg_task_app: FastAPI,
217197
async_client: AsyncClient,
218-
base_client: BaseClient,
198+
base_client: HttpClient,
219199
router_prefix: str,
220200
) -> None:
221201
task_id = await _create_and_get_taskid(async_client, endpoint="failing")

0 commit comments

Comments
 (0)