fangwenxue
V2EX  ›  问与答

Python apscheduler 用 RedisJobStore 问题

  •  
  •   fangwenxue · Sep 18, 2022 · 1146 views
    This topic created in 1357 days ago, the information mentioned may be changed or developed.
    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 为什么没有打印?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:21 · PVG 14:21 · LAX 23:21 · JFK 02:21
    ♥ Do have faith in what you're doing.