Skip to content

Commit

Permalink
Use AppKey in aiohttp 3.9 (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
JCHacking authored Nov 18, 2023
1 parent c1156e1 commit 58e16fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 58e16fa

Please sign in to comment.