|
@@ -6,7 +6,6 @@ import functools
|
|
|
import inspect
|
|
|
import logging
|
|
|
import threading
|
|
|
-from abc import ABC, abstractmethod
|
|
|
from typing import (
|
|
|
Any,
|
|
|
Callable,
|
|
@@ -14,7 +13,6 @@ from typing import (
|
|
|
Generator,
|
|
|
Generic,
|
|
|
Iterable,
|
|
|
- List,
|
|
|
Mapping,
|
|
|
Optional,
|
|
|
Tuple,
|
|
@@ -43,12 +41,6 @@ REGION_NAME_LENGTH = 48
|
|
|
DEFAULT_DATE = datetime.datetime(2000, 1, 1)
|
|
|
|
|
|
|
|
|
-class InterfaceWithLifecycle(ABC):
|
|
|
- @abstractmethod
|
|
|
- def close(self) -> None:
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
def report_pydantic_type_validation_error(
|
|
|
field: pydantic.fields.ModelField,
|
|
|
value: Any,
|
|
@@ -170,7 +162,7 @@ class RpcModel(pydantic.BaseModel):
|
|
|
return cls(**fields)
|
|
|
|
|
|
|
|
|
-ServiceInterface = TypeVar("ServiceInterface", bound=InterfaceWithLifecycle)
|
|
|
+ServiceInterface = TypeVar("ServiceInterface")
|
|
|
|
|
|
|
|
|
class DelegatedBySiloMode(Generic[ServiceInterface]):
|
|
@@ -204,7 +196,6 @@ class DelegatedBySiloMode(Generic[ServiceInterface]):
|
|
|
yield
|
|
|
finally:
|
|
|
with self._lock:
|
|
|
- self.close(silo_mode)
|
|
|
self._singleton[silo_mode] = prev
|
|
|
|
|
|
def __getattr__(self, item: str) -> Any:
|
|
@@ -214,28 +205,11 @@ class DelegatedBySiloMode(Generic[ServiceInterface]):
|
|
|
if impl := self._singleton.get(cur_mode, None):
|
|
|
return getattr(impl, item)
|
|
|
if con := self._constructors.get(cur_mode, None):
|
|
|
- self.close(cur_mode)
|
|
|
self._singleton[cur_mode] = inst = con()
|
|
|
return getattr(inst, item)
|
|
|
|
|
|
raise KeyError(f"No implementation found for {cur_mode}.")
|
|
|
|
|
|
- def close(self, mode: SiloMode | None = None) -> None:
|
|
|
- to_close: List[ServiceInterface] = []
|
|
|
- with self._lock:
|
|
|
- if mode is None:
|
|
|
- to_close.extend(s for s in self._singleton.values() if s is not None)
|
|
|
- self._singleton = dict()
|
|
|
- else:
|
|
|
- existing = self._singleton.get(mode)
|
|
|
- if existing:
|
|
|
- to_close.append(existing)
|
|
|
- self._singleton = self._singleton.copy()
|
|
|
- self._singleton[mode] = None
|
|
|
-
|
|
|
- for service in to_close:
|
|
|
- service.close()
|
|
|
-
|
|
|
|
|
|
hc_test_stub: Any = threading.local()
|
|
|
|
|
@@ -256,9 +230,6 @@ def CreateStubFromBase(
|
|
|
def __init__(self: Any, backing_service: ServiceInterface) -> None:
|
|
|
self.backing_service = backing_service
|
|
|
|
|
|
- def close(self: Any) -> None:
|
|
|
- self.backing_service.close()
|
|
|
-
|
|
|
def make_method(method_name: str) -> Any:
|
|
|
def method(self: Any, *args: Any, **kwds: Any) -> Any:
|
|
|
from sentry.services.hybrid_cloud.auth import AuthenticationContext
|
|
@@ -285,7 +256,6 @@ def CreateStubFromBase(
|
|
|
if getattr(getattr(Super, name), "__isabstractmethod__", False):
|
|
|
methods[name] = make_method(name)
|
|
|
|
|
|
- methods["close"] = close
|
|
|
methods["__init__"] = __init__
|
|
|
|
|
|
return cast(
|