gpt4 book ai didi

python - APScheduler 随机关闭

转载 作者:行者123 更新时间:2023-12-04 06:48:19 25 4
gpt4 key购买 nike

调度程序在生产中运行良好,然后突然关闭。显然,DB 可能已经离线了一段时间(网络应用程序从未错过任何一个节拍,因此它是短暂的)。

日志报告...

[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 存储库上发现了与您的问题非常相似的内容。
https://github.com/agronholm/apscheduler/issues/109

此处的问题似乎已在 version 3.3 中得到缓解和合并.

您所要做的就是至少升级到 3.3 .
如果您愿意 更改默认 10 秒 间隔那么你必须设置jobstore_retry_interval当您创建调度程序实例时。

如果你不能升级,那么我会尝试猴子修补APScheduler中的相应功能。

def monkey_patched_process_jobs(self):

# You have alter the way job processing done in this function.

pass

# replacing the function with the patched one
BackgroundScheduler._process_jobs = monkey_patched_process_jobs

scheduler = BackgroundScheduler()

请记住,这并不理想,如果由于重大更改而无法升级,我只会进行猴子修补。

此功能如何在幕后工作

这是 APScheduler Git 存储库中的一个片段
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_retry_interval按以下方式设置:
self.jobstore_retry_interval = float(config.pop('jobstore_retry_interval', 10))

关于python - APScheduler 随机关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59059931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com