mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
Scan job discovery only looked at the high priority queue and only recognised scan_platforms, so two kinds of in-flight scan went unseen. Watcher scans are delayed through the scheduler and land in the low priority queue, so the concurrency guard let a manual scan start alongside one and the stop handler left it queued to run afterwards. The scheduled rescan enqueues its own task and calls scan_platforms in process, so the worker reports the task's name. That made stopping it a silent no-op: with no running job matched, the stop flag it polls was never set. Discovery now spans both queues plus the scheduler and matches either function name. The scheduler registry also holds the standing cron entry for the scheduled rescan, which is a schedule rather than a pending scan, so only delayed scan_platforms jobs count as queued. Clearing the stop flag at scan start is now scoped to the scan that owns it, so a scan starting next to one that has not yet polled the flag cannot drop a stop request meant for it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
from config import (
|
|
ENABLE_SCHEDULED_RESCAN,
|
|
SCHEDULED_RESCAN_CRON,
|
|
)
|
|
from endpoints.sockets.scan import ScanStats, scan_platforms
|
|
from handler.metadata import (
|
|
meta_flashpoint_handler,
|
|
meta_hasheous_handler,
|
|
meta_hltb_handler,
|
|
meta_igdb_handler,
|
|
meta_launchbox_handler,
|
|
meta_libretro_handler,
|
|
meta_moby_handler,
|
|
meta_playmatch_handler,
|
|
meta_ra_handler,
|
|
meta_sgdb_handler,
|
|
meta_ss_handler,
|
|
meta_tgdb_handler,
|
|
)
|
|
from handler.scan_handler import MetadataSource, ScanType
|
|
from logger.logger import log
|
|
from tasks.tasks import SCAN_LIBRARY_TASK_FUNC, PeriodicTask, TaskType
|
|
|
|
|
|
class ScanLibraryTask(PeriodicTask):
|
|
def __init__(self):
|
|
super().__init__(
|
|
title="Scheduled rescan",
|
|
description="Rescans the entire library",
|
|
task_type=TaskType.SCAN,
|
|
enabled=ENABLE_SCHEDULED_RESCAN,
|
|
manual_run=False,
|
|
cron_string=SCHEDULED_RESCAN_CRON,
|
|
func=SCAN_LIBRARY_TASK_FUNC,
|
|
)
|
|
|
|
async def run(self) -> dict[str, str]:
|
|
scan_stats = ScanStats()
|
|
|
|
if not ENABLE_SCHEDULED_RESCAN:
|
|
log.info("Scheduled library scan not enabled, unscheduling...")
|
|
self.unschedule()
|
|
return scan_stats.to_dict()
|
|
|
|
source_mapping: dict[str, bool] = {
|
|
MetadataSource.IGDB: meta_igdb_handler.is_enabled(),
|
|
MetadataSource.SS: meta_ss_handler.is_enabled(),
|
|
MetadataSource.MOBY: meta_moby_handler.is_enabled(),
|
|
MetadataSource.RA: meta_ra_handler.is_enabled(),
|
|
MetadataSource.LAUNCHBOX: meta_launchbox_handler.is_enabled(),
|
|
MetadataSource.HASHEOUS: meta_hasheous_handler.is_enabled(),
|
|
MetadataSource.PLAYMATCH: meta_playmatch_handler.is_enabled(),
|
|
MetadataSource.SGDB: meta_sgdb_handler.is_enabled(),
|
|
MetadataSource.FLASHPOINT: meta_flashpoint_handler.is_enabled(),
|
|
MetadataSource.HLTB: meta_hltb_handler.is_enabled(),
|
|
MetadataSource.TGDB: meta_tgdb_handler.is_enabled(),
|
|
MetadataSource.LIBRETRO: meta_libretro_handler.is_enabled(),
|
|
}
|
|
|
|
metadata_sources = [source for source, flag in source_mapping.items() if flag]
|
|
if not metadata_sources:
|
|
log.warning("No metadata sources enabled, unscheduling library scan")
|
|
return scan_stats.to_dict()
|
|
|
|
log.info("Scheduled library scan started...")
|
|
scan_stats = await scan_platforms(
|
|
platform_ids=[],
|
|
metadata_sources=metadata_sources,
|
|
scan_type=ScanType.QUICK,
|
|
)
|
|
log.info("Scheduled library scan done")
|
|
|
|
return scan_stats.to_dict()
|
|
|
|
|
|
scan_library_task = ScanLibraryTask()
|