Python 自动调度程序随机关闭
调度程序在生产中运行良好,然后突然关闭。很明显,DB可能已经离线了一段时间(web应用程序从未错过任何节拍,所以它是暂时的) 日志报告Python 自动调度程序随机关闭,python,apscheduler,Python,Apscheduler,调度程序在生产中运行良好,然后突然关闭。很明显,DB可能已经离线了一段时间(web应用程序从未错过任何节拍,所以它是暂时的) 日志报告 [2019-11-25 07:59:14,907: INFO/ercscheduler] Scheduler has been shut down [2019-11-25 07:59:14,908: DEBUG/ercscheduler] Looking for jobs to run [2019-11-25 07:59:14,909: WARNING/ercs
[2019-11-25 07:59:14,907: INFO/ercscheduler] Scheduler has been shut down
[2019-11-25 07:59:14,908: DEBUG/ercscheduler] Looking for jobs to run
[2019-11-25 07:59:14,909: WARNING/ercscheduler] Error getting due jobs from job store 'default': (psycopg2.OperationalError) could not connect to server: Network is unreachable
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 6432?
(Background on this error at: http://sqlalche.me/e/e3q8)
[2019-11-25 07:59:14,909: DEBUG/ercscheduler] Next wakeup is due at 2019-11-25 13:59:24.908318+00:00 (in 10.000000 seconds)
[2019-11-25 07:59:14,909: INFO/ercscheduler] listener closed
[2019-11-25 07:59:14,909: INFO/ercscheduler] server has terminated
[2019-11-25 08:00:10,747: INFO/ercscheduler] Adding job tentatively -- it will be properly scheduled when the scheduler starts
[2019-11-25 08:00:10,797: INFO/ercscheduler] Adding job tentatively -- it will be properly scheduled when the scheduler starts
[2019-11-26 15:27:48,392: INFO/ercscheduler] Adding job tentatively -- it will be properly scheduled when the scheduler starts
[2019-11-26 15:27:48,392: INFO/ercscheduler] Adding job tentatively -- it will be properly scheduled when the scheduler starts
如何使计划程序更具容错性?我必须重新启动守护进程才能继续运行。我在APScheduler Github repo上发现了与您的问题非常类似的问题。 这个问题似乎在
版本3.3
中得到缓解和合并。
您所要做的就是升级到至少3.3
。
如果要更改默认的10秒间隔,则必须在创建调度程序实例时设置jobstore\u retry\u间隔
如果您无法升级,那么我将尝试在ApsScheduler中修补相应的函数。
请记住,这不是理想的,我只会做猴子补丁,如果我无法升级,由于破坏性的变化
此功能在引擎盖下的工作原理 这是ApsScheduler Git repo的一个片段
try:
due_jobs = jobstore.get_due_jobs(now)
except Exception as e:
# Schedule a wakeup at least in jobstore_retry_interval seconds
self._logger.warning('Error getting due jobs from job store %r: %s',
jobstore_alias, e)
retry_wakeup_time = now + timedelta(seconds=self.jobstore_retry_interval)
if not next_wakeup_time or next_wakeup_time > retry_wakeup_time:
next_wakeup_time = retry_wakeup_time
continue
self.jobstore\u retry\u间隔
按以下方式设置:
self.jobstore_retry_interval = float(config.pop('jobstore_retry_interval', 10))
如果是这样的话,我会假设在日志中我会看到“从作业库获取到期作业时出错”。有没有可能我的postgres DB离线超过10秒,而我使用的是默认设置或10秒,它只是停止处理。我希望调度器永远不要停止连接postgres的尝试,这样,除非DB崩溃,否则调度器将重新启动。这可能吗?
self.jobstore_retry_interval = float(config.pop('jobstore_retry_interval', 10))