Skip to content

Commit 14e6a54

Browse files
author
Andrei Neagu
committed
refactor positions
1 parent 1380367 commit 14e6a54

File tree

9 files changed

+43
-42
lines changed

9 files changed

+43
-42
lines changed

packages/service-library/src/servicelib/long_running_interfaces/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
ResultModel,
77
StartParams,
88
)
9-
from ._rpc.server import BaseServerJobInterface
109
from ._server import Server
10+
from .runners.base import BaseServerJobInterface
1111

1212
__all__ = (
1313
"BaseServerJobInterface",

packages/service-library/src/servicelib/long_running_interfaces/_rpc/server.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import traceback
2-
from abc import ABC, abstractmethod
32
from datetime import timedelta
4-
from typing import Any
53

64
from servicelib.rabbitmq import RPCRouter
75
from settings_library.rabbit import RabbitSettings
@@ -17,39 +15,10 @@
1715
ResultModel,
1816
StartParams,
1917
)
18+
from ..runners.base import BaseServerJobInterface
2019
from ._utils import get_rpc_namespace
2120

2221

23-
class BaseServerJobInterface(ABC):
24-
"""allows the server side jobs to be implemented however the user pleases"""
25-
26-
@abstractmethod
27-
async def start(
28-
self,
29-
name: RemoteHandlerName,
30-
unique_id: JobUniqueId,
31-
params: StartParams,
32-
timeout: timedelta, # noqa: ASYNC109
33-
) -> None:
34-
"""used to start a job"""
35-
36-
@abstractmethod
37-
async def remove(self, unique_id: JobUniqueId) -> None:
38-
"""aborts and removes a job"""
39-
40-
@abstractmethod
41-
async def is_present(self, unique_id: JobUniqueId) -> bool:
42-
"""returns True if the job exists"""
43-
44-
@abstractmethod
45-
async def is_running(self, unique_id: JobUniqueId) -> bool:
46-
"""returns True if the job is currently running"""
47-
48-
@abstractmethod
49-
async def get_result(self, unique_id: JobUniqueId) -> Any | None:
50-
"""provides the result of the job once finished"""
51-
52-
5322
class ServerRPCInterface:
5423
def __init__(
5524
self,

packages/service-library/src/servicelib/long_running_interfaces/_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from settings_library.rabbit import RabbitSettings
22

33
from ._models import LongRunningNamespace
4-
from ._rpc.server import BaseServerJobInterface, ServerRPCInterface
4+
from ._rpc.server import ServerRPCInterface
5+
from .runners.base import BaseServerJobInterface
56

67

78
class Server:
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55

66
from pydantic import NonNegativeFloat
77

8-
from ...async_utils import cancel_wait_task
9-
from ...long_running_interfaces import (
10-
BaseServerJobInterface,
11-
JobUniqueId,
12-
RemoteHandlerName,
13-
StartParams,
14-
)
8+
from ....async_utils import cancel_wait_task
9+
from ..._models import JobUniqueId, RemoteHandlerName, StartParams
10+
from ...runners.base import BaseServerJobInterface
1511
from ._errors import HandlerNotRegisteredError, TaskNotFoundError
1612
from ._registry import AsyncTaskRegistry
1713

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Callable
22
from typing import Any, Self, TypeVar
33

4-
from ...long_running_interfaces import RemoteHandlerName
4+
from ..._models import RemoteHandlerName
55

66
DecoratedCallable = TypeVar("DecoratedCallable", bound=Callable[..., Any])
77

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from abc import ABC, abstractmethod
2+
from datetime import timedelta
3+
from typing import Any
4+
5+
from .._models import JobUniqueId, RemoteHandlerName, StartParams
6+
7+
8+
class BaseServerJobInterface(ABC):
9+
"""allows the server side jobs to be implemented however the user pleases"""
10+
11+
@abstractmethod
12+
async def start(
13+
self,
14+
name: RemoteHandlerName,
15+
unique_id: JobUniqueId,
16+
params: StartParams,
17+
timeout: timedelta, # noqa: ASYNC109
18+
) -> None:
19+
"""used to start a job"""
20+
21+
@abstractmethod
22+
async def remove(self, unique_id: JobUniqueId) -> None:
23+
"""aborts and removes a job"""
24+
25+
@abstractmethod
26+
async def is_present(self, unique_id: JobUniqueId) -> bool:
27+
"""returns True if the job exists"""
28+
29+
@abstractmethod
30+
async def is_running(self, unique_id: JobUniqueId) -> bool:
31+
"""returns True if the job is currently running"""
32+
33+
@abstractmethod
34+
async def get_result(self, unique_id: JobUniqueId) -> Any | None:
35+
"""provides the result of the job once finished"""

0 commit comments

Comments
 (0)