aio web server fixes.
This commit is contained in:
@@ -6,13 +6,14 @@ import sys
|
||||
import traceback
|
||||
from io import BytesIO
|
||||
|
||||
from app import DB_CLIENT, LOGGER, Config, Message
|
||||
from app.core.decorators.add_cmd import AddCmd
|
||||
from app.utils.aiohttp_tools import aio
|
||||
from pyrogram import Client, filters, idle
|
||||
from pyrogram.enums import ParseMode
|
||||
from pyrogram.types import Message as Msg
|
||||
|
||||
from app import DB_CLIENT, LOGGER, Config, Message
|
||||
from app.core.decorators.add_cmd import AddCmd
|
||||
from app.utils.aiohttp_tools import aio
|
||||
|
||||
|
||||
def import_modules():
|
||||
for py_module in glob.glob(pathname="app/**/[!^_]*.py", recursive=True):
|
||||
@@ -67,6 +68,7 @@ class BOT(Client, AddCmd):
|
||||
LOGGER.info("Idling...")
|
||||
await idle()
|
||||
await aio.session.close()
|
||||
await aio.runner.cleanup()
|
||||
LOGGER.info("DB Closed.")
|
||||
DB_CLIENT.close()
|
||||
|
||||
@@ -100,6 +102,7 @@ class BOT(Client, AddCmd):
|
||||
await super().stop(block=False)
|
||||
LOGGER.info("Closing DB...")
|
||||
DB_CLIENT.close()
|
||||
await aio.runner.cleanup()
|
||||
if hard:
|
||||
os.remove("logs/app_logs.txt")
|
||||
os.execl("/bin/bash", "/bin/bash", "run")
|
||||
|
||||
@@ -12,7 +12,6 @@ class Aio:
|
||||
def __init__(self):
|
||||
self.session: ClientSession | None = None
|
||||
self.app = None
|
||||
self.site = None
|
||||
self.port = os.environ.get("API_PORT", 0)
|
||||
self.runner = None
|
||||
if self.port:
|
||||
@@ -28,8 +27,10 @@ class Aio:
|
||||
self.app.router.add_get(path="/", handler=self.handle_request)
|
||||
self.runner = web.AppRunner(self.app)
|
||||
await self.runner.setup()
|
||||
self.site = web.TCPSite(self.runner, "0.0.0.0", self.port)
|
||||
await self.site.start()
|
||||
site = web.TCPSite(
|
||||
self.runner, "0.0.0.0", self.port, reuse_address=True, reuse_port=True
|
||||
)
|
||||
await site.start()
|
||||
|
||||
async def handle_request(self, _):
|
||||
return web.Response(text="Web Server Running...")
|
||||
|
||||
Reference in New Issue
Block a user