Add try except when closing program

This commit is contained in:
Joakim Hellsén 2022-12-06 12:37:20 +01:00
commit a9a6884d39
No known key found for this signature in database
GPG key ID: 01FD861E3DAC09AC
2 changed files with 9 additions and 3 deletions

View file

@ -165,7 +165,7 @@ def send_to_discord(feed=None) -> None:
raise
try:
webhook_url: str = str(reader.get_tag(entry.feed.url, "webhook"))
webhook_url: str = str(reader.get_tag(entry.feed_url, "webhook"))
except TagNotFoundError:
logger.error("Tag not found", exc_info=True)
raise

View file

@ -37,7 +37,7 @@ from fastapi import FastAPI, Form, HTTPException, Request
from fastapi.responses import FileResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from reader import EntryCounts, Feed, FeedCounts, ResourceNotFoundError
from reader import EntryCounts, Feed, FeedCounts, ReaderError, ResourceNotFoundError
from starlette.templating import _TemplateResponse
from tomlkit.toml_document import TOMLDocument
@ -254,8 +254,14 @@ def shutdown() -> None:
It stops the scheduler."""
scheduler: BackgroundScheduler = BackgroundScheduler()
scheduler.shutdown()
logger.info("Scheduler stopped.")
try:
reader.close()
except ReaderError:
logger.error("Error closing reader.", exc_info=True)
sys.exit()
logger.info("Reader closed.")
if __name__ == "__main__":