This repository was archived by the owner on Jul 24, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 1
- from asyncio import get_event_loop
1
+ from asyncio import create_task , get_event_loop
2
2
from glob import glob
3
3
4
4
from aiohttp import web
8
8
from WebStreamer .bot .client import initialize_clients
9
9
from WebStreamer .logger import LOGGER
10
10
from WebStreamer .server import web_server
11
+ from WebStreamer .utils import ping_server
11
12
from WebStreamer .vars import Vars
12
13
13
14
files = glob ("WebStreamer/bot/plugins/*.py" )
@@ -27,6 +28,8 @@ async def start_services():
27
28
if bot_info .dc_id :
28
29
LOGGER .info (f"DC ID =>> { str (bot_info .dc_id )} " )
29
30
await initialize_clients ()
31
+ if Vars .KEEP_ALIVE :
32
+ create_task (ping_server ())
30
33
await server .setup ()
31
34
await web .TCPSite (server , Vars .BIND_ADDRESS , Vars .PORT ).start ()
32
35
LOGGER .info ("Service Started" )
Original file line number Diff line number Diff line change
1
+ from asyncio import sleep
2
+
3
+ from aiohttp import ClientSession , ClientTimeout
4
+
5
+ from WebStreamer .logger import LOGGER
6
+ from WebStreamer .vars import Vars
7
+
8
+
9
+ async def ping_server ():
10
+ sleep_time = Vars .PING_INTERVAL
11
+ LOGGER .info (f"Started with { sleep_time } s interval between pings" )
12
+ while True :
13
+ await sleep (sleep_time )
14
+ try :
15
+ async with ClientSession (timeout = ClientTimeout (total = 10 )) as session :
16
+ async with session .get (Vars .URL ) as resp :
17
+ LOGGER .info (f"Pinged server with response: { resp .status } " )
18
+ except TimeoutError :
19
+ LOGGER .warning ("Couldn't connect to the site URL.." )
20
+ except Exception :
21
+ LOGGER .error ("Unexpected error: " , exc_info = True )
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ class Vars:
17
17
18
18
# Bot tokens
19
19
BOT_TOKEN = str (config ("BOT_TOKEN" , default = None ))
20
- # Bot tokens end
21
-
20
+ PING_INTERVAL = int ( config ( "PING_INTERVAL" , default = 0 )) # should be in seconds
21
+ KEEP_ALIVE = PING_INTERVAL != 0
22
22
SLEEP_THRESHOLD = int (config ("SLEEP_THRESHOLD" , default = 60 ))
23
23
WORKERS = int (config ("WORKERS" , default = 8 ))
24
24
LOG_CHANNEL = int (config ("LOG_CHANNEL" , default = - 100 ))
You can’t perform that action at this time.
0 commit comments