Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AppKey in aiohttp 3.9 #460

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aiojobs/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
_T = TypeVar("_T")
_RequestView = TypeVar("_RequestView", bound=Union[web.Request, web.View])

# TODO(aiohttp 3.9+): Use AppKey

AIOJOBS_SCHEDULER = web.AppKey("AIOJOBS_SCHEDULER", Scheduler)


def get_scheduler(request: web.Request) -> Scheduler:
Expand All @@ -31,11 +32,11 @@ def get_scheduler(request: web.Request) -> Scheduler:


def get_scheduler_from_app(app: web.Application) -> Optional[Scheduler]:
return app.get("AIOJOBS_SCHEDULER")
return app.get(AIOJOBS_SCHEDULER)


def get_scheduler_from_request(request: web.Request) -> Optional[Scheduler]:
return request.config_dict.get("AIOJOBS_SCHEDULER") # type: ignore[no-any-return]
return request.config_dict.get(AIOJOBS_SCHEDULER)


async def spawn(request: web.Request, coro: Coroutine[object, object, _T]) -> Job[_T]:
Expand All @@ -62,7 +63,7 @@ async def wrapper(request_or_view: _RequestView) -> _T:

def setup(app: web.Application, **kwargs: Any) -> None:
async def cleanup_context(app: web.Application) -> AsyncIterator[None]:
app["AIOJOBS_SCHEDULER"] = scheduler = Scheduler(**kwargs)
app[AIOJOBS_SCHEDULER] = scheduler = Scheduler(**kwargs)
yield
await scheduler.close()

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install_requires =

[options.extras_require]
aiohttp =
aiohttp >= 3.8.0
aiohttp >= 3.9.0

[flake8]
ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E704,W503,W504,F811
Expand Down