Skip to content

Commit d7233f6

Browse files
committed
Upgraded starlette and dropped on_request_started and on_request_finished
1 parent d062a8a commit d7233f6

File tree

16 files changed

+5
-297
lines changed

16 files changed

+5
-297
lines changed

ellar/common/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
extra_args,
1414
file,
1515
middleware,
16-
on_shutdown,
17-
on_startup,
1816
openapi_info,
1917
render,
2018
serializer_filter,
@@ -89,8 +87,6 @@
8987
"middleware",
9088
"exception_handler",
9189
"serializer_filter",
92-
"on_shutdown",
93-
"on_startup",
9490
"template_filter",
9591
"template_global",
9692
"Res",

ellar/common/decorators/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .middleware import middleware
1212
from .modules import Module
1313
from .openapi import openapi_info
14-
from .request import on_shutdown, on_startup
1514
from .serializer import serializer_filter
1615
from .versioning import Version
1716

@@ -24,9 +23,7 @@
2423
"template_global",
2524
"file",
2625
"render",
27-
"on_startup",
2826
"exception_handler",
29-
"on_shutdown",
3027
"command",
3128
"set_metadata",
3229
"middleware",

ellar/common/decorators/request.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

ellar/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ def __new__(mcls, name, bases, namespace):
6464
RESPONSE_OVERRIDE_KEY = "RESPONSE_OVERRIDE"
6565
EXCEPTION_HANDLERS_KEY = "EXCEPTION_HANDLERS"
6666

67-
ON_REQUEST_STARTUP_KEY = "ON_REQUEST_STARTUP"
68-
ON_REQUEST_SHUTDOWN_KEY = "ON_REQUEST_SHUTDOWN"
69-
7067
TEMPLATE_GLOBAL_KEY = "TEMPLATE_GLOBAL_FILTERS"
7168
TEMPLATE_FILTER_KEY = "TEMPLATE_FILTERS"
7269

ellar/core/conf/app_settings_models.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
from ellar.serializer import Serializer, SerializerFilter
1212
from ellar.types import ASGIApp, TReceive, TScope, TSend
1313

14-
from .mixins import (
15-
ConfigDefaultTypesMixin,
16-
TEventHandler,
17-
TExceptionHandler,
18-
TMiddleware,
19-
TVersioning,
20-
)
14+
from .mixins import ConfigDefaultTypesMixin, TExceptionHandler, TMiddleware, TVersioning
2115

2216
if t.TYPE_CHECKING: # pragma: no cover
2317
from ellar.core.main import App
@@ -113,9 +107,6 @@ class Config:
113107
# logging Level
114108
LOG_LEVEL: t.Optional[log_levels] = log_levels.info
115109

116-
ON_REQUEST_STARTUP: t.List[TEventHandler] = []
117-
ON_REQUEST_SHUTDOWN: t.List[TEventHandler] = []
118-
119110
TEMPLATE_FILTERS: t.Dict[str, t.Callable[..., t.Any]] = {}
120111
TEMPLATE_GLOBAL_FILTERS: t.Dict[str, t.Callable[..., t.Any]] = {}
121112

ellar/core/conf/mixins.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ class ConfigDefaultTypesMixin:
126126
# defines other custom json encoders
127127
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]]
128128

129-
# will be set automatically when @on_startup is found in a Module class
130-
ON_REQUEST_STARTUP: t.List[TEventHandler]
131-
132-
# will be set automatically when @on_shutdown is found in a Module class
133-
ON_REQUEST_SHUTDOWN: t.List[TEventHandler]
134-
135129
# will be set automatically when @template_filter is found in a Module class
136130
TEMPLATE_FILTERS: t.Dict[str, t.Callable[..., t.Any]]
137131

ellar/core/factory.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,9 @@ def _get_config_kwargs() -> t.Dict:
137137

138138
cls._build_modules(app_module=module, injector=injector, config=config)
139139

140-
shutdown_event = config.ON_REQUEST_STARTUP
141-
startup_event = config.ON_REQUEST_SHUTDOWN
142-
143140
app = App(
144141
config=config,
145142
injector=injector,
146-
on_shutdown_event_handlers=shutdown_event if shutdown_event else None,
147-
on_startup_event_handlers=startup_event if startup_event else None,
148143
lifespan=config.DEFAULT_LIFESPAN_HANDLER,
149144
global_guards=global_guards,
150145
)

ellar/core/main.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from ellar.core.templating import AppTemplating, Environment
3030
from ellar.core.versioning import BaseAPIVersioning, VersioningSchemes
3131
from ellar.di.injector import EllarInjector
32-
from ellar.events import EventHandler, RouterEventManager
3332
from ellar.logger import logger
3433
from ellar.types import ASGIApp, T, TReceive, TScope, TSend
3534

@@ -41,8 +40,6 @@ def __init__(
4140
self,
4241
config: "Config",
4342
injector: EllarInjector,
44-
on_startup_event_handlers: t.Optional[t.Sequence[EventHandler]] = None,
45-
on_shutdown_event_handlers: t.Optional[t.Sequence[EventHandler]] = None,
4643
lifespan: t.Optional[t.Callable[["App"], t.AsyncContextManager]] = None,
4744
global_guards: t.List[
4845
t.Union[t.Type[GuardCanActivate], GuardCanActivate]
@@ -53,12 +50,6 @@ def __init__(
5350
injector, EllarInjector
5451
), "injector must instance of EllarInjector"
5552

56-
# The lifespan context function is a newer style that replaces
57-
# on_startup / on_shutdown handlers. Use one or the other, not both.
58-
assert lifespan is None or (
59-
on_startup_event_handlers is None and on_shutdown_event_handlers is None
60-
), "Use either 'lifespan' or 'on_startup'/'on_shutdown', not both."
61-
6253
self._config = config
6354
self._injector: EllarInjector = injector
6455

@@ -67,15 +58,6 @@ def __init__(
6758

6859
self._user_middleware = list(t.cast(list, self.config.MIDDLEWARE))
6960

70-
self.on_startup = RouterEventManager(
71-
[] if on_startup_event_handlers is None else list(on_startup_event_handlers)
72-
)
73-
self.on_shutdown = RouterEventManager(
74-
[]
75-
if on_shutdown_event_handlers is None
76-
else list(on_shutdown_event_handlers)
77-
)
78-
7961
self._static_app: t.Optional[ASGIApp] = None
8062

8163
self.state = State()
@@ -85,12 +67,6 @@ def __init__(
8567
self.router = ApplicationRouter(
8668
routes=self._get_module_routes(),
8769
redirect_slashes=self.config.REDIRECT_SLASHES,
88-
on_startup=[self.on_startup.async_run]
89-
if self.config.DEFAULT_LIFESPAN_HANDLER is None
90-
else None,
91-
on_shutdown=[self.on_shutdown.async_run]
92-
if self.config.DEFAULT_LIFESPAN_HANDLER is None
93-
else None,
9470
default=self.config.DEFAULT_NOT_FOUND_HANDLER, # type: ignore
9571
lifespan=self.config.DEFAULT_LIFESPAN_HANDLER,
9672
)

ellar/core/modules/builder.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
EXCEPTION_HANDLERS_KEY,
55
MIDDLEWARE_HANDLERS_KEY,
66
MODULE_FIELDS,
7-
ON_REQUEST_SHUTDOWN_KEY,
8-
ON_REQUEST_STARTUP_KEY,
97
TEMPLATE_FILTER_KEY,
108
TEMPLATE_GLOBAL_KEY,
119
)
12-
from ellar.events import EventHandler
1310
from ellar.reflect import reflect
1411

1512
from ..exceptions.callable_exceptions import CallableExceptionHandler
@@ -34,8 +31,6 @@ def __init__(self, cls: t.Union[t.Type["ModuleBase"], "ModuleBaseMeta"]) -> None
3431
{
3532
EXCEPTION_HANDLERS_KEY: self.exception_config,
3633
MIDDLEWARE_HANDLERS_KEY: self.middleware_config,
37-
ON_REQUEST_SHUTDOWN_KEY: self.on_request_shut_down_config,
38-
ON_REQUEST_STARTUP_KEY: self.on_request_startup_config,
3934
TEMPLATE_GLOBAL_KEY: self.template_global_config,
4035
TEMPLATE_FILTER_KEY: self.template_filter_config,
4136
},
@@ -57,26 +52,6 @@ def middleware_config(self, middleware: "MiddlewareSchema") -> None:
5752
self._cls,
5853
)
5954

60-
def on_request_shut_down_config(self, on_shutdown_event: EventHandler) -> None:
61-
on_shutdown_event.handler = module_callable_factory(
62-
on_shutdown_event.handler, self._cls
63-
)
64-
reflect.define_metadata(
65-
ON_REQUEST_SHUTDOWN_KEY,
66-
[on_shutdown_event],
67-
self._cls,
68-
)
69-
70-
def on_request_startup_config(self, on_startup_event: EventHandler) -> None:
71-
on_startup_event.handler = module_callable_factory(
72-
on_startup_event.handler, self._cls
73-
)
74-
reflect.define_metadata(
75-
ON_REQUEST_STARTUP_KEY,
76-
[on_startup_event],
77-
self._cls,
78-
)
79-
8055
def template_filter_config(self, template_filter: "TemplateFunctionData") -> None:
8156
reflect.define_metadata(
8257
TEMPLATE_FILTER_KEY,

ellar/core/modules/ref.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
MODULE_METADATA,
1313
MODULE_REF_TYPES,
1414
MODULE_WATERMARK,
15-
ON_REQUEST_SHUTDOWN_KEY,
16-
ON_REQUEST_STARTUP_KEY,
1715
TEMPLATE_FILTER_KEY,
1816
TEMPLATE_GLOBAL_KEY,
1917
)
@@ -28,8 +26,7 @@
2826
from .base import ModuleBase, ModuleBaseMeta
2927

3028
if t.TYPE_CHECKING: # pragma: no cover
31-
from ellar.conf import Config
32-
from ellar.core import ControllerBase
29+
from ellar.core import Config, ControllerBase
3330

3431

3532
class InvalidModuleTypeException(Exception):
@@ -194,7 +191,6 @@ def __init__(
194191
self._flatten_routes: t.List[BaseRoute] = []
195192

196193
self.scan_templating_filters()
197-
self.scan_request_events()
198194
self.scan_exceptions_handlers()
199195
self.scan_middleware()
200196
self.register_providers()
@@ -301,22 +297,3 @@ def _get_all_routers(self) -> t.Sequence[t.Union[ModuleMount, Mount, BaseRoute]]
301297
) and isinstance(controller, ControllerType), "Invalid Controller Type."
302298
_routers.append(controller_router_factory(controller))
303299
return _routers
304-
305-
def scan_request_events(self) -> None:
306-
request_startup = (
307-
reflect.get_metadata(ON_REQUEST_STARTUP_KEY, self._module_type) or []
308-
)
309-
if not self._config.get(ON_REQUEST_STARTUP_KEY) or not isinstance(
310-
self._config[ON_REQUEST_STARTUP_KEY], list
311-
):
312-
self._config[ON_REQUEST_STARTUP_KEY] = []
313-
self._config[ON_REQUEST_STARTUP_KEY].extend(request_startup)
314-
315-
request_shutdown = (
316-
reflect.get_metadata(ON_REQUEST_SHUTDOWN_KEY, self._module_type) or []
317-
)
318-
if not self._config.get(ON_REQUEST_SHUTDOWN_KEY) or not isinstance(
319-
self._config[ON_REQUEST_SHUTDOWN_KEY], list
320-
):
321-
self._config[ON_REQUEST_SHUTDOWN_KEY] = []
322-
self._config[ON_REQUEST_SHUTDOWN_KEY].extend(request_shutdown)

0 commit comments

Comments
 (0)