41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import logging
|
||
from config import config_manager
|
||
from utils.plex_utils import PlexManager
|
||
from .cache_service import CacheManager
|
||
|
||
log = logging.getLogger(__name__)
|
||
|
||
def update_all_plex_libraries_cache():
|
||
"""
|
||
强制刷新所有已配置的Plex媒体库的缓存。
|
||
这个函数将被定时任务调用。
|
||
"""
|
||
log.info("开始执行定时任务:更新Plex媒体库缓存...")
|
||
plex_config = config_manager.get('plex')
|
||
if not plex_config or not plex_config.get('host'):
|
||
log.info("Plex未配置,跳过更新任务。")
|
||
return
|
||
|
||
try:
|
||
manager = PlexManager(plex_config)
|
||
libraries = manager.get_libraries()
|
||
|
||
for lib in libraries:
|
||
lib_id = lib['id']
|
||
# 为每个媒体库创建一个独立的缓存文件
|
||
cache_mgr = CacheManager(f"plex_lib_{lib_id}.json")
|
||
|
||
# 调用 get_data 并传入真正的 fetch 函数,这会强制刷新缓存
|
||
log.debug(f"正在为Plex媒体库 '{lib['name']}' ({lib_id}) 刷新缓存...")
|
||
cache_mgr.get_data(manager.get_library_items, library_id=lib_id)
|
||
|
||
log.info("Plex媒体库缓存更新任务完成。")
|
||
|
||
except Exception as e:
|
||
log.error(f"更新Plex缓存时发生错误: {e}", exc_info=True)
|
||
|
||
# TODO: 在这里添加其他更新函数,例如:
|
||
# def update_local_skits_cache():
|
||
# log.info("开始更新本地短剧缓存...")
|
||
# ...
|