Skip to content

Commit

Permalink
convert function which run in executor to task
Browse files Browse the repository at this point in the history
  • Loading branch information
erezz-mov-ai committed Aug 9, 2023
1 parent 9107b13 commit ead399a
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions backend/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def post_token_auth(self, request: web.Request) -> web.Response:
output = {}
status = 200
try:
await self._run_blocking_code(request, TokenManager.remove_all_expired_tokens)
asyncio.create_task(TokenManager.remove_all_expired_tokens())

data = await request.json()
domain = data["domain"].lower()
Expand Down Expand Up @@ -247,19 +247,5 @@ def get_domains(self, request: web.Request) -> web.Response:
output["domains"] = AUTH_MANAGER.get_domains()
return web.json_response(output, headers={"Server": "Movai-server"})

async def _run_blocking_code(self, request: web.Request, func: callable, *args) -> any:
"""Runs a blocking function that may take long time.
Args:
func (callable): The function to run.
Returns:
Any: The return value of the function.
"""
executor = request.app["executor"]
loop = asyncio.get_event_loop()
future = loop.run_in_executor(executor, func, *args)
await future


WebAppManager.register("/auth/", AuthApp)

0 comments on commit ead399a

Please sign in to comment.