All checks were successful
Gitea Actions Demo / deploy (push) Successful in 14s
37 lines
987 B
Python
37 lines
987 B
Python
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
|
|
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
|
|
from loguru import logger
|
|
from config.settings import settings
|
|
|
|
SCHEDULER_DB_URL = (
|
|
f"postgresql+psycopg://{settings.DB_USER}:{settings.DB_PASS}"
|
|
f"@{settings.DB_HOST}:{settings.DB_PORT}/{settings.DB_NAME}"
|
|
)
|
|
|
|
def create_scheduler():
|
|
job_stores = {
|
|
"default": SQLAlchemyJobStore(url=SCHEDULER_DB_URL)
|
|
}
|
|
|
|
executors = {
|
|
"default": ThreadPoolExecutor(10),
|
|
"processpool": ProcessPoolExecutor(2)
|
|
}
|
|
|
|
job_defaults = {
|
|
"coalesce": False, # 重叠任务处理
|
|
"max_instances": 3
|
|
}
|
|
|
|
scheduler = BackgroundScheduler(
|
|
jobstores=job_stores,
|
|
executors=executors,
|
|
job_defaults=job_defaults,
|
|
timezone=settings.TIMEZONE,
|
|
)
|
|
|
|
return scheduler
|
|
|
|
|
|
scheduler = create_scheduler() |