main: Use get_published_events query.

This commit is contained in:
Giacomo Leidi 2021-05-31 01:19:24 +02:00
parent c129edd1e5
commit dd664089d8
2 changed files with 11 additions and 1 deletions

View File

@ -5,6 +5,7 @@ from tortoise import run_async
from mobilizon_bots.config.config import settings
from mobilizon_bots.storage.db import MobilizonBotsDB
from mobilizon_bots.storage.query import get_published_events
logger = logging.getLogger(__name__)
@ -17,7 +18,7 @@ async def main():
logging.config.dictConfig(settings.logging)
db = MobilizonBotsDB(Path(settings.db_path))
await db.setup()
published_events = db.get_published_events()
published_events = get_published_events()
unpublished_events = get_unpublished_events(published_events)
event = select_event_to_publish()
result = PublisherCoordinator(event).publish() if event else exit(0)

View File

@ -1,3 +1,5 @@
import asyncio
import atexit
import logging
from pathlib import Path
@ -34,3 +36,10 @@ class MobilizonBotsDB:
await Tortoise.generate_schemas()
self.is_init = True
logger.info(f"Succesfully initialized database at {self.path}")
@atexit.register
def gracefully_tear_down():
logger.info("Shutting down DB")
loop = asyncio.get_event_loop()
loop.run_until_complete(Tortoise.close_connections())