feat: implement post-init function for application startup tasks

- Added _post_init function to run startup tasks, including restoring group pin jobs and resolving bot username.
- Updated main function to utilize the new _post_init for improved application initialization process.
This commit is contained in:
2026-03-04 18:38:20 +03:00
parent 6d087d1b26
commit 8ad8dffd0a

View File

@@ -19,6 +19,12 @@ from duty_teller.utils.http_client import safe_urlopen
_HTTP_STARTUP_WAIT_SEC = 3
async def _post_init(application) -> None:
"""Run startup tasks: restore group pin jobs, then resolve bot username."""
await group_duty_pin.restore_group_pin_jobs(application)
await _resolve_bot_username(application)
async def _resolve_bot_username(application) -> None:
"""If BOT_USERNAME is not set from env, resolve it via get_me()."""
if not config.BOT_USERNAME:
@@ -101,8 +107,7 @@ def main() -> None:
app = (
ApplicationBuilder()
.token(config.BOT_TOKEN)
.post_init(group_duty_pin.restore_group_pin_jobs)
.post_init(_resolve_bot_username)
.post_init(_post_init)
.build()
)
register_handlers(app)