我正在构建一个应用程序,并尝试使用Redis/python-rq/rq-scheduler设置计划任务。
我可以很好地设置一个队列,如下所示:
from redis import Redis
from rq import Queue
rq = Queue(connection=Redis(host=BaseConfig.REDIS_HOST, port=BaseConfig.REDIS_PORT))
def hello_world():
print("hello world")
@app.route("/queue/test", method=["GET", "POST"])
def test_queue():
job = rq.enqueue_call(func=hello_world)
return jsonify(job_id=job.id())但是现在,当我尝试设置一个计划任务时,根据这里的文档link。如下所示:
from datetime import timedelta
from redis import Redis
from rq import Queue
from rq_scheduler import Scheduler
rq = Queue(connection=Redis(host=BaseConfig.REDIS_HOST, port=BaseConfig.REDIS_PORT))
rqs = Scheduler(queue=rq)
def hello_world():
print("hello world")
@app.route("/queue/test", method=["GET", "POST"])
def test_queue():
job = rqs.enqueue_in(timedelta(seconds=30), func=hello_world)
return jsonify(job_id=job.id())我得到了
raise NoRedisConnectionException('Could not resolve a Redis connection')
rq.connections.NoRedisConnectionException: Could not resolve a Redis connection所有的帮助都将不胜感激。谢谢。
发布于 2020-04-07 17:45:06
创建scheduler对象时需要传递连接
https://stackoverflow.com/questions/50570157
复制相似问题