LiKenun's picture
Move more components into dependency injection container
c21d29c
raw
history blame
1.08 kB
from asyncio import run
from loguru import logger
from ctp_slack_bot.containers import Container
from ctp_slack_bot.core.logging import setup_logging
async def main() -> None:
# Setup logging.
setup_logging()
logger.info("Starting application…")
# Set up dependency injection container.
container = Container()
container.wire(packages=['ctp_slack_bot'])
# Kick off services which should be active from the start.
container.content_ingestion_service()
container.question_dispatch_service()
# Start the scheduler.
schedule_service = container.schedule_service()
schedule_service.start()
# Start the Slack socket mode handler in a background thread.
socket_mode_handler = container.socket_mode_handler()
logger.info("Starting Slack Socket Mode handler…")
await socket_mode_handler.start_async()
# Shutdown. (This will never execute, because the socket mode handler never returns.)
logger.info("Shutting down application…")
schedule_service.stop()
if __name__ == "__main__":
run(main())