Let "sync" command override resync_max_disconnected_time

This commit is contained in:
Andrew Ferrazzutti 2022-05-05 03:28:44 -04:00
parent 9a82db2257
commit 5ae5970ef0
2 changed files with 6 additions and 6 deletions

View File

@ -114,7 +114,7 @@ async def sync(evt: CommandEvent) -> None:
return return
await evt.mark_read() await evt.mark_read()
if await evt.sender.connect_and_sync(sync_count): if await evt.sender.connect_and_sync(sync_count, force_sync=True):
await evt.reply("Sync complete") await evt.reply("Sync complete")
else: else:
await evt.reply("Sync failed") await evt.reply("Sync failed")

View File

@ -472,7 +472,7 @@ class User(DBUser, BaseUser):
sync_count = self.config["bridge.initial_chat_sync"] sync_count = self.config["bridge.initial_chat_sync"]
else: else:
sync_count = None sync_count = None
await self.connect_and_sync(sync_count) await self.connect_and_sync(sync_count, force_sync=False)
else: else:
await self.send_bridge_notice( await self.send_bridge_notice(
f"Logged into KakaoTalk. To connect to chatroom updates, use the `sync` command." f"Logged into KakaoTalk. To connect to chatroom updates, use the `sync` command."
@ -488,11 +488,11 @@ class User(DBUser, BaseUser):
} if self.ktid else {} } if self.ktid else {}
@async_time(METRIC_CONNECT_AND_SYNC) @async_time(METRIC_CONNECT_AND_SYNC)
async def connect_and_sync(self, sync_count: int | None) -> bool: async def connect_and_sync(self, sync_count: int | None, force_sync: bool) -> bool:
# TODO Look for a way to sync all channels without (re-)logging in # TODO Look for a way to sync all channels without (re-)logging in
try: try:
login_result = await self.client.connect() login_result = await self.client.connect()
should_sync = await self.on_connect() should_sync = await self.on_connect(force_sync)
if login_result and should_sync: if login_result and should_sync:
await self._sync_channels(login_result, sync_count) await self._sync_channels(login_result, sync_count)
return True return True
@ -696,7 +696,7 @@ class User(DBUser, BaseUser):
# region KakaoTalk event handling # region KakaoTalk event handling
async def on_connect(self) -> bool: async def on_connect(self, force_sync: bool) -> bool:
now = time.monotonic() now = time.monotonic()
disconnected_at = self._connection_time disconnected_at = self._connection_time
max_delay = self.config["bridge.resync_max_disconnected_time"] max_delay = self.config["bridge.resync_max_disconnected_time"]
@ -704,7 +704,7 @@ class User(DBUser, BaseUser):
self.is_connected = True self.is_connected = True
self._track_metric(METRIC_CONNECTED, True) self._track_metric(METRIC_CONNECTED, True)
duration = int(now - disconnected_at) duration = int(now - disconnected_at)
skip_sync = not first_connect and duration < max_delay skip_sync = not first_connect and not force_sync and duration < max_delay
if skip_sync: if skip_sync:
self.log.debug(f"Disconnection lasted {duration} seconds, not re-syncing channels...") self.log.debug(f"Disconnection lasted {duration} seconds, not re-syncing channels...")
elif self.temp_disconnect_notices: elif self.temp_disconnect_notices: