Files
FileStreamBot/FileStream/utils/keepalive.py

21 lines
664 B
Python
Raw Normal View History

2022-01-02 19:22:16 +05:30
import asyncio
2021-06-05 11:56:44 +05:30
import logging
2022-01-02 19:22:16 +05:30
import aiohttp
import traceback
from FileStream.config import Server
2022-01-02 19:22:16 +05:30
async def ping_server():
sleep_time = Server.PING_INTERVAL
2022-01-02 19:22:16 +05:30
while True:
await asyncio.sleep(sleep_time)
2022-01-02 19:22:16 +05:30
try:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10)
) as session:
async with session.get(Server.URL) as resp:
2022-01-02 19:22:16 +05:30
logging.info("Pinged server with response: {}".format(resp.status))
except TimeoutError:
logging.warning("Couldn't connect to the site URL..!")
except Exception:
traceback.print_exc()