V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
fangwenxue
V2EX  ›  问与答

Python apscheduler 用 RedisJobStore 问题

  •  
  •   fangwenxue · 2022-09-18 21:03:27 +08:00 · 489 次点击
    这是一个创建于 578 天前的主题,其中的信息可能已经有所发展或是发生改变。
    redis_uri = config.LOCAL_REDIS_URI or config.REDIS_URI
    connection_pool = ConnectionPool.from_url(redis_uri)
    job_store = RedisJobStore(connection_pool=connection_pool)
    job_stores = {'default': job_store}
    
    scheduler = BlockingScheduler(timezone='Asia/Shanghai', jobstores=job_stores)
    
    
    def check_new_job():
        print(scheduler.get_jobs())
        with open('text.txt', 'a+') as f:
            f.write(f'{time.time()}\n')
    
    
    def run():
        scheduler.add_job(check_new_job, 'interval', seconds=5, id='job_test2', next_run_time=datetime.now(),
                          replace_existing=True)
    
        scheduler.start()
    
    • 如果用默认的 MemoryJobStore 打印跟写入的时间戳都正常
    • 用 RedisJobStore 没有打印,文件写没有写入时间戳,redis 是正常的,可以看到 job 写到 redis 了
    • 第一次运用会有打印跟写入,5 秒后的下一次运行就没有打印与写入
    • 关掉程序,在运行同样没有打印与写入
    • RedisJobStore 为什么没有打印?
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2802 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 11:48 · PVG 19:48 · LAX 04:48 · JFK 07:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.