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:
@@ -19,6 +19,12 @@ from duty_teller.utils.http_client import safe_urlopen
|
|||||||
_HTTP_STARTUP_WAIT_SEC = 3
|
_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:
|
async def _resolve_bot_username(application) -> None:
|
||||||
"""If BOT_USERNAME is not set from env, resolve it via get_me()."""
|
"""If BOT_USERNAME is not set from env, resolve it via get_me()."""
|
||||||
if not config.BOT_USERNAME:
|
if not config.BOT_USERNAME:
|
||||||
@@ -101,8 +107,7 @@ def main() -> None:
|
|||||||
app = (
|
app = (
|
||||||
ApplicationBuilder()
|
ApplicationBuilder()
|
||||||
.token(config.BOT_TOKEN)
|
.token(config.BOT_TOKEN)
|
||||||
.post_init(group_duty_pin.restore_group_pin_jobs)
|
.post_init(_post_init)
|
||||||
.post_init(_resolve_bot_username)
|
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
register_handlers(app)
|
register_handlers(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user