118 lines
3.2 KiB
Python
118 lines
3.2 KiB
Python
from typing import Callable, List, Optional, Union
|
|
|
|
from .container import Container
|
|
from .method import Method
|
|
from .value import Value
|
|
|
|
|
|
class MethodCallError:
|
|
__slots__ = ('msg', )
|
|
|
|
msg: Optional[str]
|
|
|
|
def __init__(self, msg: Optional[str] = None) -> None:
|
|
self.msg = msg
|
|
|
|
def __repr__(self) -> str:
|
|
return f'{self.__class__.__name__}({repr(self.msg)})'
|
|
|
|
|
|
class ServiceNotFoundError(MethodCallError):
|
|
"""
|
|
The service was not found
|
|
|
|
You have an `@imported('service_name')` somewhere,
|
|
but there is no `service_name` deployed to the platform.
|
|
"""
|
|
|
|
|
|
class MethodNotFoundError(MethodCallError):
|
|
"""
|
|
The method was not found
|
|
|
|
You have an `@imported('service_name')` somewhere,
|
|
but while the `service_name` is deployed to the platform,
|
|
it does not provide the given function.
|
|
"""
|
|
|
|
|
|
class MethodTypeMismatchError(MethodCallError):
|
|
"""
|
|
The method's type did not match
|
|
|
|
You have an `@imported('service_name')` somewhere,
|
|
but there while the `service_name` is deployed to the platform,
|
|
and the service does provide the function,
|
|
its type does not match what you defined in your import.
|
|
"""
|
|
|
|
|
|
class ServiceUnavailableError(MethodCallError):
|
|
"""
|
|
The service was not available
|
|
|
|
You have an `@imported('service_name')` somewhere,
|
|
but there while the `service_name` is deployed to the platform,
|
|
and the service does provide the function,
|
|
and its type matches what you defined in your import,
|
|
there is currently no container running providing said service.
|
|
"""
|
|
|
|
|
|
class MethodCallExceptionError(MethodCallError):
|
|
"""
|
|
The service was not available
|
|
|
|
You have an `@imported('service_name')` somewhere,
|
|
but there while the `service_name` is deployed to the platform,
|
|
and the service does provide the function,
|
|
and its type matches what you defined in your import,
|
|
and there is currently a container running providing said service,
|
|
when it tried to run the call, an exeption ocurred.
|
|
"""
|
|
|
|
|
|
class MethodCall:
|
|
__slots__ = ('method', 'args', )
|
|
|
|
method: Method
|
|
args: List[Value]
|
|
|
|
def __init__(
|
|
self,
|
|
method: Method,
|
|
args: List[Value],
|
|
) -> None:
|
|
self.method = method
|
|
self.args = args
|
|
|
|
def __repr__(self) -> str:
|
|
return f'MethodCall({repr(self.method)}, {repr(self.args)})'
|
|
|
|
|
|
MethodResultCallable = Callable[[Union[Value, MethodCallError]], None]
|
|
|
|
|
|
class RoutedMethodCall:
|
|
__slots__ = ('call', 'from_container', 'to_container', 'on_result', )
|
|
|
|
call: MethodCall
|
|
from_container: Optional[Container]
|
|
to_container: Optional[Container]
|
|
on_result: MethodResultCallable
|
|
|
|
def __init__(
|
|
self,
|
|
call: MethodCall,
|
|
from_container: Optional[Container],
|
|
to_container: Optional[Container],
|
|
on_result: MethodResultCallable,
|
|
) -> None:
|
|
self.call = call
|
|
self.from_container = from_container
|
|
self.to_container = to_container
|
|
self.on_result = on_result
|
|
|
|
def __repr__(self) -> str:
|
|
return f'RoutedMethodCall({repr(self.call)}, {repr(self.from_container)}, {repr(self.to_container)}, {repr(self.on_result)})'
|