Files
cksd/scheduler.py

42 lines
971 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import logging
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from tasks.water_ammeter import SD
logger = logging.getLogger("scheduler")
sd = SD()
def start_scheduler():
logger.info("初始化 AsyncIOSchedulerAsia/Shanghai")
scheduler = AsyncIOScheduler(timezone="Asia/Shanghai")
scheduler.add_job(
sd.fetch_and_save,
trigger="cron",
minute="0",
id="water_ammeter_job",
replace_existing=True,
max_instances=1,
coalesce=True,
)
logger.info("已添加任务water_ammeter_job每小时整点执行")
scheduler.add_job(
sd.push,
trigger="cron",
hour=8,
minute=30,
id="push_gzh",
replace_existing=True,
max_instances=1,
coalesce=True,
)
logger.info("已添加任务push_gzh每天 08:00 执行)")
scheduler.start()
logger.info("调度器启动完成")
return scheduler