From f97ee4311a1f9a308eb275c3c586fea071596c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=84?= Date: Fri, 7 Aug 2020 16:43:37 +0800 Subject: [PATCH 1/2] Add timezone config for the scheduler --- handler/configHandler.py | 4 ++++ helper/scheduler.py | 6 ++++-- setting.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/handler/configHandler.py b/handler/configHandler.py index a391ffb45..7c79470ef 100644 --- a/handler/configHandler.py +++ b/handler/configHandler.py @@ -57,3 +57,7 @@ def verifyTimeout(self): @LazyProperty def maxFailCount(self): return os.getenv("MAX_FAIL_COUNT", setting.MAX_FAIL_COUNT) + + @LazyProperty + def timezone(self): + return os.getenv("TIMEZONE", getattr(setting, 'TIMEZONE', None)) diff --git a/helper/scheduler.py b/helper/scheduler.py index 9051bd97f..d8c62eefc 100644 --- a/helper/scheduler.py +++ b/helper/scheduler.py @@ -12,6 +12,7 @@ """ __author__ = 'JHao' +from handler.configHandler import ConfigHandler from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.executors.pool import ProcessPoolExecutor @@ -44,8 +45,9 @@ def runProxyCheck(): def runScheduler(): runProxyFetch() + timezone = ConfigHandler().timezone scheduler_log = LogHandler("scheduler") - scheduler = BlockingScheduler(logger=scheduler_log) + scheduler = BlockingScheduler(logger=scheduler_log, timezone=timezone) scheduler.add_job(runProxyFetch, 'interval', minutes=4, id="proxy_fetch", name="proxy采集") scheduler.add_job(runProxyCheck, 'interval', minutes=2, id="proxy_check", name="proxy检查") @@ -59,7 +61,7 @@ def runScheduler(): 'max_instances': 10 } - scheduler.configure(executors=executors, job_defaults=job_defaults) + scheduler.configure(executors=executors, job_defaults=job_defaults, timezone=timezone) scheduler.start() diff --git a/setting.py b/setting.py index 9eb8690af..13be0b2c0 100644 --- a/setting.py +++ b/setting.py @@ -67,3 +67,13 @@ MAX_FAIL_COUNT = 0 +# ############# scheduler config ################# + +# Set the timezone for the scheduler forcely (optional) +# If it is running on a VM, and +# "ValueError: Timezone offset does not match system offset" +# was raised during scheduling. +# Please uncomment the following line and set a timezone for the scheduler. +# Otherwise it will detect the timezone from the system automatically. + +# TIMEZONE = "Asia/Shanghai" \ No newline at end of file From 11ad82c050c6b680500395498da375f2fb85f7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=84?= Date: Fri, 7 Aug 2020 16:46:29 +0800 Subject: [PATCH 2/2] Eof newline --- setting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setting.py b/setting.py index 13be0b2c0..79e67aca3 100644 --- a/setting.py +++ b/setting.py @@ -76,4 +76,4 @@ # Please uncomment the following line and set a timezone for the scheduler. # Otherwise it will detect the timezone from the system automatically. -# TIMEZONE = "Asia/Shanghai" \ No newline at end of file +# TIMEZONE = "Asia/Shanghai"