[F] Fix RuntimeError: Timeout context manager should be used inside a task
https://github.com/dashezup/github-webhook-to-telegram/issues/3
This commit is contained in:
@@ -43,24 +43,15 @@ async def github_webhook_post_handler(request: Request) -> Response:
|
|||||||
tg_chat_id: Union[str, int, bool] = await validate_github_webhook(request)
|
tg_chat_id: Union[str, int, bool] = await validate_github_webhook(request)
|
||||||
if not tg_chat_id:
|
if not tg_chat_id:
|
||||||
return web.Response(status=403, text="403: Forbidden")
|
return web.Response(status=403, text="403: Forbidden")
|
||||||
tg_status = await send_to_telegram(session, tg_chat_id, request)
|
async with ClientSession() as session:
|
||||||
|
tg_status = await send_to_telegram(session, tg_chat_id, request)
|
||||||
return web.Response(text=f"Send to Telegram: {tg_status}")
|
return web.Response(text=f"Send to Telegram: {tg_status}")
|
||||||
|
|
||||||
|
|
||||||
async def get_session() -> ClientSession:
|
|
||||||
return ClientSession()
|
|
||||||
|
|
||||||
|
|
||||||
async def on_shutdown(_):
|
|
||||||
await session.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
|
# FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
|
||||||
# logging.basicConfig(level=logging.INFO, format=FORMAT)
|
# logging.basicConfig(level=logging.INFO, format=FORMAT)
|
||||||
session: ClientSession \
|
|
||||||
= asyncio.get_event_loop().run_until_complete(get_session())
|
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app.add_routes(routes)
|
app.add_routes(routes)
|
||||||
app.on_shutdown.append(on_shutdown)
|
|
||||||
web.run_app(app, port=PORT)
|
web.run_app(app, port=PORT)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user