Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurdok committed Sep 3, 2024
1 parent f646d08 commit e8f982c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/spanreed/plugins/spanreed_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def run_for_user(self, user: User) -> None:
async def _monitor_exceptions(self, user: User) -> None:
bot: TelegramBotApi = await TelegramBotApi.for_user(user)
await bot.send_message("Spanreed is starting up.")

interval: datetime.timedelta = datetime.timedelta(days=1, hours=6)

try:
Expand Down Expand Up @@ -82,7 +82,11 @@ async def _monitor_obsidian_plugin(self, user: User) -> None:
time_since_last_watchdog_message = (
datetime.datetime.now() - last_watchdog_message
)
if time_since_last_watchdog > base_timeout and time_since_last_watchdog_message > datetime.timedelta(minutes=30):
if (
time_since_last_watchdog > base_timeout
and time_since_last_watchdog_message
> datetime.timedelta(minutes=30)
):
await bot.send_message("Obsidian plugin watchdog timeout.")
last_watchdog_message = datetime.datetime.now()
timeout = base_timeout
Expand All @@ -98,14 +102,20 @@ async def _monitor_obsidian_plugin(self, user: User) -> None:
if event["kind"] == "error":
self._logger.info(f"Obsidian plugin error: {event}")
time_since_last_obsidian_error_message = (
datetime.datetime.now() - last_obsidian_error_message
datetime.datetime.now()
- last_obsidian_error_message
)
if time_since_last_obsidian_error_message > datetime.timedelta(minutes=30):
if (
time_since_last_obsidian_error_message
> datetime.timedelta(minutes=30)
):
await redis_api.lpush(
self.EXCEPTION_QUEUE_NAME,
f"Obsidian plugin error: {event}",
)
last_obsidian_error_message = datetime.datetime.now()
last_obsidian_error_message = (
datetime.datetime.now()
)
elif event["kind"] == "watchdog":
self._logger.info(
"Obsidian plugin watchdog event received."
Expand Down

0 comments on commit e8f982c

Please sign in to comment.