Skip to content

Commit

Permalink
fix CronTrigger.from_crontab异常捕捉
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 22, 2023
1 parent 29df081 commit ea160af
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/plugins/cloudflarespeedtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,25 @@ def init_plugin(self, config: dict = None):
if self.get_state() or self._onlyonce:
self._scheduler = BackgroundScheduler(timezone=settings.TZ)

if self.get_state() and self._cron:
logger.info(f"Cloudflare CDN优选服务启动,周期:{self._cron}")
self._scheduler.add_job(func=self.__cloudflareSpeedTest,
trigger=CronTrigger.from_crontab(self._cron),
name="Cloudflare优选")

if self._onlyonce:
logger.info(f"Cloudflare CDN优选服务启动,立即运行一次")
self._scheduler.add_job(func=self.__cloudflareSpeedTest, trigger='date',
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
name="Cloudflare优选")
# 关闭一次性开关
self._onlyonce = False
self.__update_config()
try:
if self.get_state() and self._cron:
logger.info(f"Cloudflare CDN优选服务启动,周期:{self._cron}")
self._scheduler.add_job(func=self.__cloudflareSpeedTest,
trigger=CronTrigger.from_crontab(self._cron),
name="Cloudflare优选")

if self._onlyonce:
logger.info(f"Cloudflare CDN优选服务启动,立即运行一次")
self._scheduler.add_job(func=self.__cloudflareSpeedTest, trigger='date',
run_date=datetime.now(tz=pytz.timezone(settings.TZ)) + timedelta(seconds=3),
name="Cloudflare优选")
# 关闭一次性开关
self._onlyonce = False
self.__update_config()
except Exception as err:
logger.error(f"Cloudflare CDN优选服务出错:{str(err)}")
self.systemmessage.put(f"Cloudflare CDN优选服务出错:{str(err)}")
return

# 启动任务
if self._scheduler.get_jobs():
Expand Down

0 comments on commit ea160af

Please sign in to comment.