Skip to content

Commit 2fdc1e9

Browse files
authored
Merge pull request #185 from grillazz/171-simple-and-fast-smtp-client
refactor SchedulerMiddleware
2 parents a7c7007 + dd619e7 commit 2fdc1e9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

app/services/scheduler.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from datetime import datetime
22

3+
from attrs import define
4+
35
from sqlalchemy import text
46
from starlette.types import ASGIApp, Receive, Scope, Send
57
from apscheduler import AsyncScheduler
@@ -20,16 +22,20 @@ async def tick():
2022
return True
2123

2224

25+
@define
2326
class SchedulerMiddleware:
24-
def __init__(
25-
self,
26-
app: ASGIApp,
27-
scheduler: AsyncScheduler,
28-
) -> None:
29-
self.app = app
30-
self.scheduler = scheduler
27+
app: ASGIApp
28+
scheduler: AsyncScheduler
3129

3230
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
31+
"""
32+
Handles the incoming request and schedules tasks if the scope type is 'lifespan'.
33+
34+
Args:
35+
scope (Scope): The ASGI scope dictionary containing request information.
36+
receive (Receive): The ASGI receive callable.
37+
send (Send): The ASGI send callable.
38+
"""
3339
if scope["type"] == "lifespan":
3440
async with self.scheduler:
3541
await self.scheduler.add_schedule(
@@ -39,3 +45,4 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
3945
await self.app(scope, receive, send)
4046
else:
4147
await self.app(scope, receive, send)
48+

0 commit comments

Comments
 (0)