redis持久化
https://www.cnblogs.com/zhufanyu/p/14011317.html
import time
## 配置redis模块
from apscheduler.jobstores.redis import RedisJobStore
## 配置线程
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
## 创建定时任务的包
from apscheduler.schedulers.background import BackgroundScheduler
def job():
# requests.get("http://127.0.0.1:8000/api/checkrequest/")
print("测试")
def job_b():
# 暂停id为a的任务
scheduler.pause_job(job_id = 'a')
for i in range(4):
print(i)
time.sleep(1)
# 恢复id为a的任务
scheduler.resume_job(job_id = 'a')
if __name__ == "__main__":
REDIS = {
'host': '127.0.0.1',
'port': '6379',
'db': 0,
'password': ''
}
jobstores = {
'redis': RedisJobStore(**REDIS)
}
executors = {
'default': ThreadPoolExecutor(10), # 默认线程数
'processpool': ProcessPoolExecutor(3) # 默认进程
}
scheduler=BackgroundScheduler(jobstores=jobstores, executors=executors)
scheduler.add_job(func=job, trigger='interval', jobstore='redis', seconds=1, id="a", coalesce=True, replace_existing=True,name="3333")
scheduler.add_job(func=job_b, trigger='interval', jobstore='redis', seconds=10, id="2", coalesce=True,
replace_existing=True, name="4444")
scheduler.start()
# 查看待运行的任务
print(scheduler.get_jobs())
time.sleep(30)
标签:__,--,redis,APScheduler,job,scheduler,import,定时,id From: https://www.cnblogs.com/kaibindirver/p/16964337.html