Fix scheduler next_run_time None check; add debug logging

- Fix race condition: next_run_time only available after scheduler.start()
- Handle None gracefully in logging
- Add debug logging to _perform_rescan and _run_rescan_job
- Document scheduler troubleshooting in DEVELOPMENT.md
This commit is contained in:
2026-05-25 13:48:34 +02:00
parent 810346bc8b
commit bda1fe4445
2 changed files with 50 additions and 2 deletions

View File

@@ -116,11 +116,13 @@ class SchedulerService:
# Startup recovery: if the server was down at the scheduled time and
# the job is within the misfire window, APScheduler will run it
# automatically. Log the scheduled time for visibility.
# Note: next_run_time is only available AFTER scheduler.start()
job = self._scheduler.get_job(_JOB_ID)
if job and job.next_run_time:
if job:
next_run = job.next_run_time
logger.info(
"Scheduler next run",
next_run=job.next_run_time.isoformat(),
next_run=next_run.isoformat() if next_run else None,
)
async def stop(self) -> None:
@@ -349,6 +351,7 @@ class SchedulerService:
async def _perform_rescan(self) -> None:
"""Execute a library rescan and optionally trigger auto-download."""
logger.info("Scheduler _perform_rescan entered", scan_in_progress=self._scan_in_progress)
if self._scan_in_progress:
logger.warning("Skipping rescan: previous scan still in progress")
return
@@ -443,6 +446,7 @@ class SchedulerService:
async def _run_rescan_job() -> None:
"""Module-level job entry point — delegates to the current service."""
logger.info("APScheduler triggered _run_rescan_job")
svc = get_scheduler_service()
await svc._perform_rescan()