diff --git a/app/plugins/autosignin/__init__.py b/app/plugins/autosignin/__init__.py index f6ebf3a4..c7f3a21f 100644 --- a/app/plugins/autosignin/__init__.py +++ b/app/plugins/autosignin/__init__.py @@ -134,20 +134,37 @@ class AutoSignIn(_PluginBase): self._start_time = int(times[0]) # 23 self._end_time = int(times[1]) - if self._start_time and self._end_time: + if self._start_time and self._end_time: + self._scheduler.add_job(func=self.sign_in, + trigger="interval", + hours=float(self._cron.strip()), + name=f"站点自动{self._action}") + logger.info( + f"站点自动{self._action}服务启动,执行周期 {self._start_time}点-{self._end_time}点 每{self._cron}小时执行一次") + else: + logger.error(f"站点自动{self._action}服务启动失败,周期格式错误") + # 推送实时消息 + self.systemmessage.put(f"执行周期配置错误") + self._cron = "" + self._enabled = False + self.__update_config() + else: + # 默认0-24 按照周期运行 + self._start_time = 0 + self._end_time = 24 self._scheduler.add_job(func=self.sign_in, trigger="interval", hours=float(self._cron.strip()), name=f"站点自动{self._action}") - logger.info(f"站点自动{self._action}服务启动,执行周期 {self._cron} {self._start_time}-{self._end_time}") - else: - logger.error(f"站点自动{self._action}服务启动失败,周期格式错误") - # 推送实时消息 - self.systemmessage.put(f"执行周期配置错误") + logger.info( + f"站点自动{self._action}服务启动,执行周期 {self._start_time}点-{self._end_time}点 每{self._cron}小时执行一次") except Exception as err: logger.error(f"定时任务配置错误:{err}") # 推送实时消息 self.systemmessage.put(f"执行周期配置错误:{err}") + self._cron = "" + self._enabled = False + self.__update_config() else: # 随机时间 triggers = TimerUtils.random_scheduler(num_executions=2, diff --git a/app/plugins/nastoolsync/__init__.py b/app/plugins/nastoolsync/__init__.py index e9ea8edc..d268e236 100644 --- a/app/plugins/nastoolsync/__init__.py +++ b/app/plugins/nastoolsync/__init__.py @@ -69,7 +69,23 @@ class NAStoolSync(_PluginBase): self.tr = Transmission() # 读取sqlite数据 - gradedb = sqlite3.connect(self._nt_db_path) + try: + gradedb = sqlite3.connect(self._nt_db_path) + except Exception as e: + self.update_config( + { + "transfer": False, + "clear": False, + "nt_db_path": None, + "path": self._path, + "downloader": self._downloader, + "site": self._site, + "supp": self._supp, + } + ) + logger.error(f"无法打开数据库文件 {self._nt_db_path},请检查路径是否正确:{e}") + return + # 创建游标cursor来执行executeSQL语句 cursor = gradedb.cursor() @@ -520,180 +536,180 @@ class NAStoolSync(_PluginBase): 拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构 """ return [ - { - 'component': 'VForm', - 'content': [ - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'transfer', - 'label': '同步记录' - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'clear', - 'label': '清空记录' - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 4 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'supp', - 'label': '补充数据' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VTextField', - 'props': { - 'model': 'nt_db_path', - 'label': 'NAStool数据库user.db路径', - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VTextarea', - 'props': { - 'model': 'path', - 'rows': '2', - 'label': '历史记录路径映射', - 'placeholder': 'NAStool路径:MoviePilot路径(一行一个)' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VTextarea', - 'props': { - 'model': 'downloader', - 'rows': '2', - 'label': '插件数据下载器映射', - 'placeholder': 'NAStool下载器id:qbittorrent|transmission(一行一个)' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VTextarea', - 'props': { - 'model': 'site', - 'label': '下载历史站点映射', - 'placeholder': 'NAStool站点名:MoviePilot站点名(一行一个)' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - }, - 'content': [ - { - 'component': 'VAlert', - 'props': { - 'text': '开启清空记录时,会在导入历史数据之前删除MoviePilot之前的记录。' - '如果转移记录很多,同步时间可能会长(3-10分钟),' - '所以点击确定后页面没反应是正常现象,后台正在处理。' - '如果开启补充数据,会获取tr、qb种子,补充转移记录中download_hash缺失的情况(同步删除需要)。' - } - } - ] - } - ] - } - ] - } - ], { - "transfer": False, - "clear": False, - "supp": False, - "nt_db_path": "", - "path": "", - "downloader": "", - "site": "", - } + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'transfer', + 'label': '同步记录' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'clear', + 'label': '清空记录' + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'supp', + 'label': '补充数据' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextField', + 'props': { + 'model': 'nt_db_path', + 'label': 'NAStool数据库user.db路径', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'path', + 'rows': '2', + 'label': '历史记录路径映射', + 'placeholder': 'NAStool路径:MoviePilot路径(一行一个)' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'downloader', + 'rows': '2', + 'label': '插件数据下载器映射', + 'placeholder': 'NAStool下载器id:qbittorrent|transmission(一行一个)' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'site', + 'label': '下载历史站点映射', + 'placeholder': 'NAStool站点名:MoviePilot站点名(一行一个)' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'text': '开启清空记录时,会在导入历史数据之前删除MoviePilot之前的记录。' + '如果转移记录很多,同步时间可能会长(3-10分钟),' + '所以点击确定后页面没反应是正常现象,后台正在处理。' + '如果开启补充数据,会获取tr、qb种子,补充转移记录中download_hash缺失的情况(同步删除需要)。' + } + } + ] + } + ] + } + ] + } + ], { + "transfer": False, + "clear": False, + "supp": False, + "nt_db_path": "", + "path": "", + "downloader": "", + "site": "", + } def get_page(self) -> List[dict]: pass diff --git a/app/plugins/sitestatistic/__init__.py b/app/plugins/sitestatistic/__init__.py index abce8a6d..5d7426de 100644 --- a/app/plugins/sitestatistic/__init__.py +++ b/app/plugins/sitestatistic/__init__.py @@ -87,14 +87,31 @@ class SiteStatistic(_PluginBase): # 加载模块 self._site_schema = ModuleHelper.load('app.plugins.sitestatistic.siteuserinfo', filter_func=lambda _, obj: hasattr(obj, 'schema')) + + # 定时服务 + self._scheduler = BackgroundScheduler(timezone=settings.TZ) + self._site_schema.sort(key=lambda x: x.order) # 站点上一次更新时间 self._last_update_time = None # 站点数据 self._sites_data = {} - # 定时服务 - self._scheduler = BackgroundScheduler(timezone=settings.TZ) - if self._cron: + + # 立即运行一次 + if self._onlyonce: + logger.info(f"站点数据统计服务启动,立即运行一次") + self._scheduler.add_job(self.refresh_all_site_data, 'date', + run_date=datetime.now( + tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3) + ) + # 关闭一次性开关 + self._onlyonce = False + + # 保存配置 + self.__update_config() + + # 周期运行 + if self._enabled and self._cron: try: self._scheduler.add_job(func=self.refresh_all_site_data, trigger=CronTrigger.from_crontab(self._cron), @@ -113,17 +130,6 @@ class SiteStatistic(_PluginBase): self._scheduler.add_job(self.refresh_all_site_data, "cron", hour=trigger.hour, minute=trigger.minute, name="站点数据统计") - if self._onlyonce: - logger.info(f"站点数据统计服务启动,立即运行一次") - self._scheduler.add_job(self.refresh_all_site_data, 'date', - run_date=datetime.now( - tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3) - ) - # 关闭一次性开关 - self._onlyonce = False - - # 保存配置 - self.__update_config() # 启动任务 if self._scheduler.get_jobs(): @@ -1034,6 +1040,9 @@ class SiteStatistic(_PluginBase): refresh_sites = [site for site in self.sites.get_indexers() if site.get("id") in self._statistic_sites] + # 过滤掉已删除的站点 + self._statistic_sites = [site.get("id") for site in refresh_sites if site] + self.__update_config() if not refresh_sites: return