Add connect-timeout config option
This commit is contained in:
parent
fac1e46859
commit
37c1052b39
|
@ -42,6 +42,10 @@ list = 1
|
||||||
auto-reconnect = yes
|
auto-reconnect = yes
|
||||||
reconnect-delay = 1.0
|
reconnect-delay = 1.0
|
||||||
|
|
||||||
|
# Change websocket connection opening timeout.
|
||||||
|
# It may be useful when initial server connection may take a long time.
|
||||||
|
connect-timeout = 60.0
|
||||||
|
|
||||||
# Number of retries in case request fails. Applies globally
|
# Number of retries in case request fails. Applies globally
|
||||||
# Can be changed on per-module basis
|
# Can be changed on per-module basis
|
||||||
http-retries = 5
|
http-retries = 5
|
||||||
|
|
|
@ -155,6 +155,7 @@ def main():
|
||||||
),
|
),
|
||||||
reconnect=conf["main"].getboolean("auto_reconnect", False),
|
reconnect=conf["main"].getboolean("auto_reconnect", False),
|
||||||
reconnect_delay=conf["main"].getfloat("reconnect_delay", 1.0),
|
reconnect_delay=conf["main"].getfloat("reconnect_delay", 1.0),
|
||||||
|
connect_timeout=conf["main"].getfloat("connect_timeout", 60.0),
|
||||||
list=conf["main"]["list"],
|
list=conf["main"]["list"],
|
||||||
access_token=conf["main"]["token"],
|
access_token=conf["main"]["token"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,8 @@ logger = getLogger("sources")
|
||||||
|
|
||||||
|
|
||||||
async def websocket_source(
|
async def websocket_source(
|
||||||
url: str, reconnect: bool = False, reconnect_delay: float = 1.0, **params
|
url: str, reconnect: bool = False, reconnect_delay: float = 1.0,
|
||||||
|
connect_timeout: float = 60.0, **params
|
||||||
) -> AsyncGenerator[Status, None]:
|
) -> AsyncGenerator[Status, None]:
|
||||||
from websockets.client import connect
|
from websockets.client import connect
|
||||||
from websockets.exceptions import WebSocketException
|
from websockets.exceptions import WebSocketException
|
||||||
|
@ -37,7 +38,7 @@ async def websocket_source(
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.info("attempting to connect to %s", public_url)
|
logger.info("attempting to connect to %s", public_url)
|
||||||
async with connect(url, open_timeout=60) as ws:
|
async with connect(url, open_timeout=connect_timeout) as ws:
|
||||||
logger.info("Connected to WebSocket")
|
logger.info("Connected to WebSocket")
|
||||||
while (msg := await ws.recv()) is not None:
|
while (msg := await ws.recv()) is not None:
|
||||||
event = loads(msg)
|
event = loads(msg)
|
||||||
|
|
Loading…
Reference in New Issue