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

10-11 02:14