【问题标题】:APScheduler shut down randomlyAPScheduler 随机关闭
【发布时间】:2019-11-26 21:55:20
【问题描述】:

调度程序在生产中运行良好,然后突然关闭。很明显,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

如何让调度器更容错?我必须再次重新启动守护程序才能让它运行。

【问题讨论】:

    标签: python apscheduler


    【解决方案1】:

    我在 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 存储库的 sn-p

    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))
    

    【讨论】:

    • 如果是这种情况,我会假设在日志中我会看到“从作业商店获取到期作业时出错”。我的 postgres 数据库是否有可能离线(比如说)超过 10 秒,而我正在使用默认值或 10 秒,它只是停止处理。我希望调度程序永远不会停止尝试连接到 postgres,这样除非数据库崩溃,否则调度程序将重新启动。这可能吗?
    猜你喜欢
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 2016-09-02
    相关资源
    最近更新 更多