Référence : Application - Catalog
src.application.catalog.catalog_sync_service
Catalog Sync Service: Facade routing requests to CatalogSyncOrchestrator. Maintains backward compatibility with all callers and tests.
CatalogSyncActions
Atomic actions executed during catalog synchronization.
fetch_mod_details(provider, page_url)
Atomic action: fetches full details for a single mod from its page URL.
scrape_category_page(provider, category, page_num)
Atomic action: scrapes a single category page from a provider. Returns a tuple of (scraped_mods_list, detected_total_pages).
update_mod_scraped_details(session, cat_mod, det_dict)
Atomic action: updates catalog mod with freshly scraped details from provider.
upsert_mods_batch(session, mods_data, default_category, invalidate_cache=True)
Atomic action: upserts a batch of mods into the CatalogMod table in a single transaction. Returns (new_count, updated_count) where updated_count reflects genuinely modified records.
CatalogSyncCoordinator
Coordinates looping, retries, delta early-stopping, and concurrency for catalog scraping.
sync_all_categories(categories, provider, max_pages, tracker, max_workers=8, is_background=False)
Coordinates worker thread execution across all categories. Returns total_new.
sync_category(category, provider, max_pages, tracker, is_background=False)
Coordinates the pagination loop for a single category, applying backoff, delta early-stopping in background mode, and calling atomic actions. Returns (cat_mods_count, cat_new_mods).
CatalogSyncOrchestrator
High-level orchestrator for catalog scraping, sync, and dependency checking.
check_dependencies(mod_title, page_url=None, source='loverslab', cat_mod=None)
Orchestrates checking dependencies for a given catalog mod.
orchestrate_sync(max_pages=-1, is_background=False, provider=None)
Orchestrates full catalog sync: 1. Identifies providers and categories (respecting adult_content_enabled setting and optional target provider). 2. Configures SyncTracker per provider. 3. Executes provider category scraping concurrently across active providers. 4. Closes sync lifecycle gracefully.
CatalogSyncService
Service applicatif pour la synchronisation et la gestion des dépendances du catalogue.
check_dependencies(mod_title, page_url=None, source='loverslab', cat_mod=None)
classmethod
Vérifie les dépendances d'un mod.
run_sync(max_pages=-1)
classmethod
Lance la synchronisation du catalogue.
SyncTracker
Thread-safe tracker for catalog synchronization progress with pause and stop support.
finish(total_new)
classmethod
Exécute l'opération finish.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_new
|
int
|
Paramètre total_new. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération finish. |
is_provider_stopped(provider=None)
classmethod
Checks whether a specific provider has been stopped or if global stop is requested.
pause(provider=None)
classmethod
Pauses background scraping workers non-CPU-intensively.
record_page(new_count, is_first_page=False)
classmethod
Exécute l'opération record page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_count
|
int
|
Paramètre new_count. |
required |
is_first_page
|
bool
|
Paramètre is_first_page. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération record_page. |
reset()
classmethod
Resets tracker state to default idle state (for tests and reinitialization).
resume(provider=None)
classmethod
Resumes background scraping workers.
set_error(message)
classmethod
Exécute l'opération set error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Paramètre message. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération set_error. |
set_provider_status(provider_name, status)
classmethod
Updates the scraping status for a specific provider.
start(max_pages, categories_list=None, max_pages_per_cat=0, active_providers=None)
classmethod
Exécute l'opération start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_pages
|
int
|
Paramètre max_pages. |
required |
categories_list
|
Optional[List[Dict[str, Any]]]
|
Paramètre categories_list. |
None
|
max_pages_per_cat
|
int
|
Paramètre max_pages_per_cat. |
0
|
active_providers
|
Optional[List[str]]
|
Liste optionnelle des providers actifs en cours de synchro. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération start. |
stop(provider=None)
classmethod
Stops background scraping workers cleanly. If a specific provider is specified, only that provider is halted, leaving others running. If provider is None, stops all running providers globally.
to_response()
classmethod
Exécute l'opération to response.
Returns:
| Type | Description |
|---|---|
CatalogSyncStatusResponse
|
Résultat de l'opération to_response. |
update_category(cat_id, pages_completed, total_pages, mods_count, status)
classmethod
Exécute l'opération update category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_id
|
str
|
Paramètre cat_id. |
required |
pages_completed
|
int
|
Paramètre pages_completed. |
required |
total_pages
|
int
|
Paramètre total_pages. |
required |
mods_count
|
int
|
Paramètre mods_count. |
required |
status
|
str
|
Paramètre status. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération update_category. |
update_progress(percent, message, current_category=None)
classmethod
Exécute l'opération update progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Paramètre percent. |
required |
message
|
str
|
Paramètre message. |
required |
current_category
|
Optional[str]
|
Paramètre current_category. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération update_progress. |
wait_if_paused()
classmethod
Blocks worker thread safely if paused until resumed, stopped, or shutting down.
check_catalog_dependencies(mod_title, page_url=None, source='loverslab', cat_mod=None)
Entry point checking dependencies via CatalogSyncOrchestrator.
run_catalog_sync(max_pages=-1, is_background=False, provider=None)
Entry point executing catalog sync via CatalogSyncOrchestrator.
src.application.catalog.sync_tracker
Thread-safe tracker for catalog synchronization progress with pause and stop support.
SyncTracker
Thread-safe tracker for catalog synchronization progress with pause and stop support.
finish(total_new)
classmethod
Exécute l'opération finish.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_new
|
int
|
Paramètre total_new. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération finish. |
is_provider_stopped(provider=None)
classmethod
Checks whether a specific provider has been stopped or if global stop is requested.
pause(provider=None)
classmethod
Pauses background scraping workers non-CPU-intensively.
record_page(new_count, is_first_page=False)
classmethod
Exécute l'opération record page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_count
|
int
|
Paramètre new_count. |
required |
is_first_page
|
bool
|
Paramètre is_first_page. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération record_page. |
reset()
classmethod
Resets tracker state to default idle state (for tests and reinitialization).
resume(provider=None)
classmethod
Resumes background scraping workers.
set_error(message)
classmethod
Exécute l'opération set error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Paramètre message. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération set_error. |
set_provider_status(provider_name, status)
classmethod
Updates the scraping status for a specific provider.
start(max_pages, categories_list=None, max_pages_per_cat=0, active_providers=None)
classmethod
Exécute l'opération start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_pages
|
int
|
Paramètre max_pages. |
required |
categories_list
|
Optional[List[Dict[str, Any]]]
|
Paramètre categories_list. |
None
|
max_pages_per_cat
|
int
|
Paramètre max_pages_per_cat. |
0
|
active_providers
|
Optional[List[str]]
|
Liste optionnelle des providers actifs en cours de synchro. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération start. |
stop(provider=None)
classmethod
Stops background scraping workers cleanly. If a specific provider is specified, only that provider is halted, leaving others running. If provider is None, stops all running providers globally.
to_response()
classmethod
Exécute l'opération to response.
Returns:
| Type | Description |
|---|---|
CatalogSyncStatusResponse
|
Résultat de l'opération to_response. |
update_category(cat_id, pages_completed, total_pages, mods_count, status)
classmethod
Exécute l'opération update category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_id
|
str
|
Paramètre cat_id. |
required |
pages_completed
|
int
|
Paramètre pages_completed. |
required |
total_pages
|
int
|
Paramètre total_pages. |
required |
mods_count
|
int
|
Paramètre mods_count. |
required |
status
|
str
|
Paramètre status. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération update_category. |
update_progress(percent, message, current_category=None)
classmethod
Exécute l'opération update progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Paramètre percent. |
required |
message
|
str
|
Paramètre message. |
required |
current_category
|
Optional[str]
|
Paramètre current_category. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Résultat de l'opération update_progress. |
wait_if_paused()
classmethod
Blocks worker thread safely if paused until resumed, stopped, or shutting down.