diff --git a/encar_scraper/encar.py b/encar_scraper/encar.py index cceaf75..783aa86 100644 --- a/encar_scraper/encar.py +++ b/encar_scraper/encar.py @@ -919,6 +919,41 @@ class EncarScraper: excluded_brands: set[str] | None = None, runtime_filters: FiltersConfig | None = None, probe_all_photos: bool = False, + ) -> dict[str, Any]: + """Публичная обёртка: гарантирует закрытие HTTP pool даже при ошибках.""" + try: + return self._sync_listing_impl( + limit=limit, + filters=filters, + lane=lane, + only_new=only_new, + batch_size=batch_size, + redis_client=redis_client, + allowed_brands=allowed_brands, + excluded_brands=excluded_brands, + runtime_filters=runtime_filters, + probe_all_photos=probe_all_photos, + ) + finally: + if self._batch_pool is not None: + try: + self._batch_pool.close() + except Exception: + logger.debug("Failed to close batch pool", exc_info=True) + self._batch_pool = None + + def _sync_listing_impl( + self, + limit: int | None = None, + filters: EncarFilters | None = None, + lane: str = "encar", + only_new: bool = False, + batch_size: int = 1000, + redis_client: Any | None = None, + allowed_brands: set[str] | None = None, + excluded_brands: set[str] | None = None, + runtime_filters: FiltersConfig | None = None, + probe_all_photos: bool = False, ) -> dict[str, Any]: """Полная синхронизация листинга Encar. @@ -1152,11 +1187,6 @@ class EncarScraper: self._clear_checkpoint(redis_client) - # Закрываем pool batch API - if self._batch_pool is not None: - self._batch_pool.close() - self._batch_pool = None - logger.info( "Full sync complete: %d shards, %d collected, %d synced, %d failed, %d marked sold", len(shards), items_collected, synced, failed, marked_sold,