Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加时区设置 #494

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions handler/configHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 4 additions & 2 deletions helper/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
__author__ = 'JHao'

from handler.configHandler import ConfigHandler
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.executors.pool import ProcessPoolExecutor

Expand Down Expand Up @@ -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检查")
Expand All @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"