Skip to content

Commit

Permalink
Sync users periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Nov 1, 2021
1 parent 7012178 commit 34257ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mautrix_telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class TelegramBridge(Bridge):
periodic_active_metrics_task: asyncio.Task
is_blocked: bool = False

periodic_sync_task: asyncio.Task

def prepare_db(self) -> None:
super().prepare_db()
init_db(self.db)
Expand Down Expand Up @@ -101,7 +103,10 @@ def prepare_bridge(self) -> None:
self.add_startup_actions(self.bot.start())
if self.config["bridge.resend_bridge_info"]:
self.add_startup_actions(self.resend_bridge_info())
self.add_startup_actions(self._loop_active_puppet_metric())

# Do not block startup on this
self.periodic_sync_task = asyncio.create_task(self._loop_active_puppet_metric())


async def resend_bridge_info(self) -> None:
self.config["bridge.resend_bridge_info"] = False
Expand All @@ -112,6 +117,7 @@ async def resend_bridge_info(self) -> None:
self.log.info("Finished re-sending bridge info state events")

def prepare_stop(self) -> None:
self.periodic_sync_task.cancel()
for puppet in Puppet.by_custom_mxid.values():
puppet.stop()
self.shutdown_actions = (user.stop() for user in User.by_tgid.values())
Expand Down

0 comments on commit 34257ae

Please sign in to comment.