Add options for controlling reconnect delay growth

This commit is contained in:
Julius Michaelis 2019-11-10 14:11:11 +09:00
parent a1abfdc3d6
commit 69ad2a9c03
3 changed files with 30 additions and 1 deletions

View file

@ -75,6 +75,8 @@ class MockConfig(object):
'print_unconfirmed_messages': None,
'read_markers_conditions': None,
'typing_notice_conditions': None,
'autoreconnect_delay_growing': None,
'autoreconnect_delay_max': None,
},
}

View file

@ -629,6 +629,26 @@ class MatrixConfig(WeechatConfig):
("Reconnect to the server if the lag is greater than this "
"value (in seconds)"),
),
Option(
"autoreconnect_delay_growing",
"integer",
"",
1,
100,
"2",
("growing factor for autoreconnect delay to server "
"(1 = always same delay, 2 = delay*2 for each retry, etc.)"),
),
Option(
"autoreconnect_delay_max",
"integer",
"",
0,
604800,
"600",
("maximum autoreconnect delay to server "
"(in seconds, 0 = no maximum)"),
),
Option(
"print_unconfirmed_messages",
"boolean",

View file

@ -671,10 +671,17 @@ class MatrixServer(object):
self.reconnect_time = time.time()
if self.reconnect_delay:
self.reconnect_delay = self.reconnect_delay * 2
self.reconnect_delay = (
self.reconnect_delay
* G.CONFIG.network.autoreconnect_delay_growing
)
else:
self.reconnect_delay = self.config.reconnect_delay
if G.CONFIG.network.autoreconnect_delay_max > 0:
self.reconnect_delay = min(self.reconnect_delay,
G.CONFIG.network.autoreconnect_delay_max)
message = (
"{prefix}matrix: reconnecting to server in {t} " "seconds"
).format(prefix=W.prefix("network"), t=self.reconnect_delay)