Add logging for entry sending and improve scheduler configuration
This commit is contained in:
parent
4be0617a01
commit
2e0157ff6c
2 changed files with 11 additions and 13 deletions
|
|
@ -352,6 +352,7 @@ def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = Non
|
||||||
feed: The feed to send to Discord.
|
feed: The feed to send to Discord.
|
||||||
do_once: If we should only send one entry. This is used in the test.
|
do_once: If we should only send one entry. This is used in the test.
|
||||||
"""
|
"""
|
||||||
|
logger.info("Starting to send entries to Discord.")
|
||||||
# Get the default reader if we didn't get a custom one.
|
# Get the default reader if we didn't get a custom one.
|
||||||
reader: Reader = get_reader() if custom_reader is None else custom_reader
|
reader: Reader = get_reader() if custom_reader is None else custom_reader
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,20 +89,17 @@ reader: Reader = get_reader()
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
|
||||||
"""Lifespan for the FastAPI app.
|
"""Lifespan function for the FastAPI app."""
|
||||||
|
|
||||||
Args:
|
|
||||||
app: The FastAPI app.
|
|
||||||
|
|
||||||
Yields:
|
|
||||||
None: Nothing.
|
|
||||||
"""
|
|
||||||
add_missing_tags(reader)
|
add_missing_tags(reader)
|
||||||
scheduler: AsyncIOScheduler = AsyncIOScheduler()
|
scheduler: AsyncIOScheduler = AsyncIOScheduler(timezone=UTC)
|
||||||
|
scheduler.add_job(
|
||||||
# Run job every minute to check for new entries. Feeds will be checked every 15 minutes.
|
func=send_to_discord,
|
||||||
# TODO(TheLovinator): Make this configurable.
|
trigger="interval",
|
||||||
scheduler.add_job(send_to_discord, "interval", minutes=1, next_run_time=datetime.now(tz=UTC))
|
minutes=1,
|
||||||
|
id="send_to_discord",
|
||||||
|
max_instances=3,
|
||||||
|
next_run_time=datetime.now(tz=UTC),
|
||||||
|
)
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
logger.info("Scheduler started.")
|
logger.info("Scheduler started.")
|
||||||
yield
|
yield
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue