Home  >  Q&A  >  body text

python - 如何解决apscheduler定时任务自动重启,导致定点执行的任务未执行完成

使用apscheduler定时执行多个任务,有的任务某个时间点执行一次,有的任务每隔一段时间执行一次;添加任务的时候使用scheduled_job装饰器,没有使用add_job方法;
现在的问题是,启动apscheduler所有的定时任务后,过一段时间,apscheduler的任务会自动重启,导致那些定点执行一次的任务没有执行完成;

执行定时任务的过程中涉及mysql查询操作,其中mysql有主从库;
从日志中查看,当定时任务查询主库的时候,apscheduler任务不会重启;而访问从库的时候,程序会重新连接数据库,定时任务就会重新加载;

难道重连mysql会导致定时任务重启????

黄舟黄舟2741 days ago1370

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 15:03:06

    misfire_grace_time The premise of this parameter is to use a sustainable jobstore. If you use the default memory jobstore, this parameter is meaningless.

    Generally, misfire_grace_time needs to be used, that is, the persistent jobstore service hangs up, and the task is not scheduled successfully when it needs to be scheduled. Later, the persistent jobstore is started, and the task is rescheduled (from the jobstore Get job), misfire_grace_time determines whether this task needs to be executed after missing the execution time

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:03:06

    Add misfire_grace_time parameter

    reply
    0
  • Cancelreply